2024-05-29 07:09:01 发布
网友
虽然将monkeypatch实例方法转换为类非常简单,例如
class A(object): pass def a(self): print "a" A.a = a
使用另一个类的@staticmethodla来执行此操作
@staticmethod
导致A.b()产生a
A.b()
TypeError: unbound method b() must be called with A instance as first argument (got nothing instead)
TypeError
b()
A
将A.b设置为静态方法,您应该可以:
A.b = staticmethod(B.b)
将A.b设置为静态方法,您应该可以:
A.b = staticmethod(B.b)
相关问题 更多 >
编程相关推荐