>>> Potato.method(self=spud, spam=123)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unbound method method() must be called with Potato instance as first argument (got nothing instead)
请注意,我没有在这里使用参数解包!在
可以很好地使用位置参数:
^{pr2}$
也可以访问原始函数对象:
>>> Potato.method.__func__(**{'self': spud, 'spam': 123})
<__main__.Potato object at 0x1002b57d0> 123
Python2的
instancemethod
包装器对象坚持检查第一个位置参数,并且该检查不支持关键字参数,句号:请注意,我没有在这里使用参数解包!在
可以很好地使用位置参数:
^{pr2}$也可以访问原始函数对象:
绕过这个限制。在
Python3不再对未绑定的方法使用方法包装器;而是直接返回底层函数。在
相关问题 更多 >
编程相关推荐