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)