How do I modify class method without touching source code?
There's a class from a library which I don't want to change the source code of.
class SomeLibraryClass(object):
def foo(self, a_var):
print self, a_var, "hello world"
Now, I want to define my own foo
method, and substitute for the original SomeLibraryClass.foo
.
def foo(obj, a_var):
print obj, a_var, "good bye"
SomeLibraryClass.foo = foo //
What should I do with the self variable?
How can I do this?