});

Override function at instance level in Python

For package development and temporary testing

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]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.