当前位置: 编程技术>python
python创建只读属性对象的方法(ReadOnlyObject)
来源: 互联网 发布时间:2014-09-04
本文导语: 代码如下:def ReadOnlyObject(**args): dictBI = {} args_n = [] for name, val in args.items(): dictBI[name] = val args_n.append(name) dictBI['__slots__'] = args_n return type('ReadOnlyObject', (object,), dictBI)()
代码如下:
def ReadOnlyObject(**args):
dictBI = {}
args_n = []
for name, val in args.items():
dictBI[name] = val
args_n.append(name)
dictBI['__slots__'] = args_n
return type('ReadOnlyObject', (object,), dictBI)()