python中動態綁定一個函數到對象

import type
class Test(object):
pass
t=Test()
def eat(self): #作爲導入方法這個self不能忘了
print(“eat”)

t.eat = types.MethodType(eat,p1)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章