标签:
先在lib文件夹中定义一个模块
1 class _const(object): 2 class ConstError(TypeError):pass 3 4 def __setattr__(self, name, value): 5 if self.__dict__.has_key(name): 6 raise self.ConstError,"Cant‘t rebind const(%s)" % name 7 self.__dict__[name]=value 8 9 def __delattr__(self, name): 10 if name in self.__dict__: 11 raise self.ConstError,"Cant‘t unbind const(%s)" % name 12 raise NameError,name 13 14 import sys 15 sys.modules[__name__]=_const()
然后新建文件,赋值,那么定义的const.value则是一个常量
import const
const.value=5
print const.value
2.变量
i=5
print i
i+=1
print i
i+=2
print i
i+=3
print i
标签:
原文地址:http://www.cnblogs.com/mylovemygirl/p/5058291.html