from types import MethodType class Temp(): def __init__(self): pass t = Temp() def methodAdd(self): print("这是要动态添加的方法") t.newMethod = MethodType(methodAdd,t) t.newMethod()
from types import MethodType class Temp(): def __init__(self): pass t = Temp() def methodAdd(self): print("这是要动态添加的方法") t.newMethod = MethodType(methodAdd,t) t.newMethod()