Some ways for binding method with instance, chose one, and loop the functions, and bind them.
base.my_fun = user_function.__get__(base)
2nd way:
import types
base.my_fun = types.MethodType(user_function, base)
3rd way:
from functools import partial
base.my_fun = partial(user_function, base)
last way:
def bind(instance, method):
def binding_scope_fn(*args, **kwargs):
return method(instance, *args, **kwargs)
return binding_scope_fn
base.my_fun = bind(base, user_function)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…