实例化类时,为什么初始化属性时会调用__getattribute__
在交互式解释器中输入如下代码:
class A:
def init(self, x):
self.dict[‘x’] = x
def getattribute(self, attr):
print(‘开始执行getattribute‘)
return object.getattribute(self, attr)
a = A(‘string’)
运行程序结果为:
开始执行getattribute
为什么?
推荐文章: