方法也是属性.__getattr__
对他们来说也是一样的:
class A(object):
def __getattr__(self, attr):
print attr
Run Code Online (Sandbox Code Playgroud)
然后尝试:
>>> a = A()
>>> a.thing
thing
>>> a.thing()
thing
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not callable
Run Code Online (Sandbox Code Playgroud)