Python Classroom image

Anil  Bist / Professional / Web Technology
 
To post your Question Join Classroom
 
Question No  (10 of 31)
First 6 I 7 I 8 I 9 I 10 I 11 I 12 I 13 I 14 Last
 
Question:-
What is monkey patching in Python?
 
Answer:-

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

Consider the below example:

1

2

3

4

# m.py

class MyClass:

def f(self):

print "f()"

We can then run the monkey-patch testing like this:

1

2

3

4

5

6

7

import m

def monkey_f(self):

print "monkey_f()"

 

m.MyClass.f = monkey_f

obj = m.MyClass()

obj.f()

The output will be as below:

monkey_f()

As we can see, we did make some changes in the behavior of f() in MyClass using the function we defined, monkey_f(), outside of the module m.

  
 
 
 
image
Anil  Bist

Skills    Python

Qualifications :- High School - SLV, College/University - Graphic Era Deemed Univ University,
Location :-Dehradun,Dehradun,Uttarakhand,
Description:-

in 2006, i Join a web development company in Bangalore and start work on "Ruby on Rail" this is my first web development framework and we worked in this framework and develop four to five project after some time , I moved to JEE/Sturst frame work,

After some time i decided that now times come and I have to go on in my own way and I started a company name is "Soarlogic&q
Explore

 

  Students (3)

Ask 
image
Vikash
Ask 
image
Anil
Ask 
image
Anil
 
 

Recommended Classes

Rajendra Kumar
I have more then 5 year of Mobile App Development Experience and have worked in Android Native, I...
Professional
image Anil Bist
in 2006, i Join a web development company in Bangalore and start work on "Ruby on Rail"...
Professional
image Sandeep Srivastava
I am working as software develop from last 9 year.worked in Java, Struts, SpringMVC, Hibernate.
Professional