- About us
How to do monkey patching in python, lets say we have a class Foo with bar method in it in module baz.
Now from outside, I can define a function monkey_bar
Now I can modify the content of bar dynamically and run as below:
baz.Foo.bar = monkey_bar
new_obj = baz.Foo()
There is a saying in python world about the dynamic typing/ duck typing "If it walks like a duck and quacks like a duck, it is a duck". With this we can say "Go on puching until it walks and quacks like a duck :)".
Python, Monkey Patching