【发布时间】:2018-03-16 16:43:59
【问题描述】:
我正在尝试在 python 中使用 getattribute 方法。
class Foo:
def __init__(self):
self.x = 3
def __getattribute__(self, name):
print("getting attribute %s" %name)
return super().__getattribute__(self, name)
f = Foo()
f.x
我打印出“获取属性”,但这里还有一个 TypeError:预期 1 个参数,得到 2 个。
那么,这个 sn-p 有什么问题呢?
【问题讨论】:
-
使用
super时,您不必将self传递给方法。
标签: python getattribute