Tob*_*ler 7 python static-methods monkeypatching
虽然将实例方法monkeypatch到类很简单,例如
class A(object):
pass
def a(self):
print "a"
A.a = a
Run Code Online (Sandbox Code Playgroud)
与其他类的这样做@staticmethod点菜
class B(object):
@staticmethod
def b():
print "static b"
A.b = B.b
Run Code Online (Sandbox Code Playgroud)
导致A.b()产生一个
TypeError:b()必须使用A实例作为第一个参数调用unbound方法(没有任何东西)
| 归档时间: |
|
| 查看次数: |
2469 次 |
| 最近记录: |