---
title: "Monkey Patching in Python"  
description: "Monkey Patching in Python"  
author: "Anonymous User"  
published: 2018-06-19  
updated: 2018-06-19  
canonical: https://www.mindstick.com/forum/34527/monkey-patching-in-python  
category: "python"  
tags: ["python"]  
reading_time: 1 minute  

---

# Monkey Patching in Python

What is Monkey patching in [Python](https://www.mindstick.com/articles/75378/simple-yet-useful-tips-when-using-python) ? give a example .

## Replies

### Reply by Prakash nidhi Verma

Monkey patching :

A dynamic modification of class module patch at run time in python this called monkey patching term.

example:

```
# m.py class MyClass:
def f(mindstick):
print "f()"
```

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

```
import m def monkey_f(mindstick):
print "monkey_f()"

m.MyClass.f = monkey_f
obj = m.MyClass()
obj.f()
```

The output will be as below:

```
monkey_f() 
```

in above example some changes in the behavior of f() in My Class using the function. monkey_f(), outside of the module m.


---

Original Source: https://www.mindstick.com/forum/34527/monkey-patching-in-python

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
