Override function at instance level in Python
For package development and temporary testing
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
from types import MethodType class Dog: def bark(self): print "WOOF" boby = Dog() boby.bark() # WOOF def newBark(self): print "WoOoOoF!!" boby.bark = MethodType(newBark, boby) boby.bark() # WoOoOoF!! |
Ref: [StackOverflow]