python中將函數動態綁定到對象,具體方法如下:
import typeclass Test(object):passt=Test()def eat(self): print(“eat”)t.eat = types.MethodType(eat,p1)
import type
class Test(object):
pass
t=Test()
def eat(self):
print(“eat”)
t.eat = types.MethodType(eat,p1)