MyClass
is defined in module.py
. There is no way we can modify it. But we do know the Class definition looks like this:
class MyClass:
def method(self, msg):
print 'from method:', msg
I start my script with importing the module and then declaring an object's instance:
import module
foo = module.MyClass()
Then I write my own function:
def function(msg):
print 'from function:', msg
Now, every time foo.method('')
is used I want to call function()
so it prints the same message too.
Would this situation be referred as the monkey patching
? How to achieve what is needed?