Last active
October 25, 2016 14:31
-
-
Save EdisonChendi/612e3cdfc2ebdd2d199ba6305b7666b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding:utf-8 | |
class _Const(object): | |
class ConstantError(TypeError): pass | |
def __setattr__(self, name, value): | |
if self.__dict__.has_key(name): | |
raise self.ConstantErrorr("can't change const value '%s'." % name) | |
if not name.isupper(): | |
raise self.ConstantError("constant name '%s' is not all uppercase." % name) | |
object.__setattr__(self, name, value) | |
const = _Const() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment