Monkey patching is the term used to denote the modifications that are done to a class or a module during the runtime. This can only be done as Python supports changes in the behavior of the program while being executed.
The following is an example, denoting monkey patching in Python:
print "func() is being called"
The above module (
monkeyy) is used to change the behavior of a function at the runtime as shown below:
print "monkey_f() is being called"
# replacing address of “
func” with “
monkeyy.X.func = monkey_f
obj = monk.X()
# calling function “
func” whose address got replaced
# with function “