在Python中,object.__getattr__()
是在屬性查找未找到self
的類樹中的屬性時調用的。如何識別__getattr__中的方法和屬性
我的問題是如何區分查找的方法和屬性。
class Test:
def __getattr__(self, name):
# How can I discern between methods and properties?
t = Test()
t.foo() # a function object should be returned
t.bar # an object should be returned
謝謝。
從屬性訪問的角度來看沒有什麼區別。方法只是屬性*太*。 –