我写了这样的代码
>>> class a(object):
def __init__(self):
self.__call__ = lambda x:x
>>> b = a()
我原以为a类的对象应该是可调用的对象,但最终却不是。
>>> b()
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
b()
TypeError: 'a' object is not callable
>>> callable(b)
False
>>> hasattr(b,'__call__')
True
>>>
我不明白为什么。请帮帮我。
https://stackoverflow.com/questions/1705928
复制相似问题