【发布时间】:2016-11-23 22:02:15
【问题描述】:
>>> class A:
... def foo(self):
... print(self)
...
>>>
>>> a = A()
>>> a.foo()
<__main__.A instance at 0x7f4399136cb0>
>>> def foo(self):
... print(self)
...
>>> a.foo = foo
>>> a.foo()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: foo() takes exactly 1 argument (0 given)
我正在尝试理解 Python 中的猴子补丁。请说明错误原因及解决方法。
【问题讨论】:
标签: python