标签:descriptor 类 python 继承
其中,__getattribute__是无条件被调用.下面给个代码片段大家自己去把玩探索.
class C(object):
def __setattr__(self, name, value):
print "__setattr__ called:", name, value
object.__setattr__(self, name, value)
def __getattr__(self, name):
print "__getattr__ called:", name
def __getattribute__(self, name):
print "__getattribute__ called:",name
return object.__getattribute__(self, name)
c = C()
c.x = "foo"
print c.__dict__['x']
print c.x
python中__get__ vs __getattr__ vs __getattribute__以及属性的搜索策略
标签:descriptor 类 python 继承
原文地址:http://blog.csdn.net/handsomekang/article/details/39929091