what is a monkey patch
from SomeOtherProduct.SomeModule import SomeClass
def speak(self):
return "ook ook eee eee eee!"
SomeClass.speak = speak
what is a monkey patch
from SomeOtherProduct.SomeModule import SomeClass
def speak(self):
return "ook ook eee eee eee!"
SomeClass.speak = speak
monkey patching in python
In Python, the term monkey patch refers to dynamic (or run-time) modifications of a class or module. In Python, we can actually change the behavior of code at run-time.
filter_none
# monk.py
class A:
def func(self):
print ("func() is being called")
We use above module (monk) in below code and change behavior of func() at run-time by assigning different value.
filter_none
import monk
def monkey_f(self):
print ("monkey_f() is being called")
# replacing address of "func" with "monkey_f"
monk.A.func = monkey_f
obj = monk.A()
# calling function "func" whose address got replaced
# with function "monkey_f()"
obj.func()
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us