After a lot of searching, I have found that there are a few ways to add an bound method or unbound class methods to an existing instance objects
Such ways include approaches the code below is taking.
import types class A(object): pass def instance_func(self): print 'hi' def class_func(self): print 'hi' a = A() # add bound methods to an instance using type.MethodType a.instance_func = types.MethodType(instance_func, a) # using attribute a.__dict__['instance_func'] = types.MethodType(instance_func, a) # using __dict__ # add bound methods to an class A.instance_func = instance_func A.__dict__['instance_func'] = instance_func # add class methods to an class A.class_func = classmethod(class_func) A.__dict__['class_func'] = classmethod(class_func) What makes me annoying is, typing the function's name, instance_func or class_func twice.
Is there any simple way to add an existing function to an class or instance without typing the function's name again?
For example, A.add_function_as_bound_method(f) will be far much elegant way to add an existing function to an instance or class since the function already has __name__ attribute.