Top MNC interview question which will be very useful for beginners to crack the interview and for there future careers

test

Breaking

Post Top Ad

Your Ad Spot

Thursday, January 7, 2021

Wipro Interview Question | Monkey Patching in Python

Question:

Demonstrate Monkey Patching in Python

Explanation:

We need to do modification of a class or module at run-time.

For Example:

            O/P: Class A monkey python function is being called.

Program:

# 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

Post Top Ad

Your Ad Spot