class _const(object):
class ConstError(TypeError):
pass
class ConstCaseError(ConstError):
pass
def __setattr__(self, key, value):
if self.__dict__.get(key):
raise self.ConstError("Can't change const.%s" % key)
print(key)
if not key.isupper():
raise self.ConstCaseError("const key %s is not all uppercase" % key)
self.__dict__[key] = value
import sys
sys.modules[__name__] = _const()
import const
const.NAME = 'python'
const.AGE = 20
const.AGE = 30
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |