标签:div get item 面向对象 对象 foo python pre dict
class Foo: def __getitem__(self, item): print(‘=====>get‘) return self.__dict__[item] def __setitem__(self, key, value): self.__dict__[key] = value # setattr(self,key,value) def __delitem__(self, key): self.__dict__.pop(key) f = Foo() f.x = 1 print(f.x) print(f.__dict__)
f[‘x‘] = 123123123123 print(f.__dict__) f[‘x‘]
del f[‘x‘] print(f[‘x‘])
python-面向对象之item系列(__getitem__,__setitem__,__delitem__)
标签:div get item 面向对象 对象 foo python pre dict
原文地址:http://www.cnblogs.com/xiechao621/p/7895612.html