Skip to content

Instantly share code, notes, and snippets.

@EdisonChendi
Last active October 25, 2016 14:31
Show Gist options
  • Save EdisonChendi/612e3cdfc2ebdd2d199ba6305b7666b7 to your computer and use it in GitHub Desktop.
Save EdisonChendi/612e3cdfc2ebdd2d199ba6305b7666b7 to your computer and use it in GitHub Desktop.
# 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