Question:
Demonstrate Monkey Patching in Python
We need to do modification of a class or module at run-time.
For Example:
# monkey.py
class A:
def functi(self):
print ("Class A monkey python function is being called.")
Driver.py
import monkey
def monkey_function(self):
print ("monkey function is being called")
monkey.A.functi = monkey_function
obj = monkey.A()
obj.functi()
---------End---------
No comments:
Post a Comment