What is monkey patching in Python?

Last updated 3 years ago | 1187 views 75     5

Tags:- Python

Python | Monkey Patching

In Python, the term monkey patch only refers to dynamic modifications of a class or module at run-time.
 

# m.py
class A:
    def func(self):
        print("Hi")



import m
def monkey(self):
    print "Hi, monkey"

m.A.func = monkey
a = m.A()
a.func()    #Hi, monkey