You should be aware that every type of class (e.g. C in class C: ... ) is an object, so you can simply overwrite class methods. As long as the instances do not overwrite their own methods (this will not happen too often, because it is not very useful for single innervations), each instance uses methods inherited from its class type. That way, you can even replace the method after creating the instance.
For example:
class C: def m(self): print "original" c1 = C() c1.m() # prints "original" def replacement(self): print "replaced!" Cm = replacement c1.m() # prints "replaced!" C().m() # prints "replaced!"
Andidog
source share