class _const(object): class ConstError(TypeError):pass def __setattr__(self,name,value): if self.__dict__.has_key(name): raise self.ConstError,"Can‘t rebind const(%s)" % name self.__dict__[name] = value def __detattr__(self,name): if name in self.__dict__: raise self.ConstError,"Can‘t unbind const(%s)" % name raise NameError,name import sys sys.modules[__name__] = _const()
时间: 2024-10-08 01:59:20