how do i add code to an existing function, either before or after?
for example, i have a class:
class A(object):
def test(self):
print
If your class A inherits from object, you could do something like:
def test2():
print "test"
class A(object):
def test(self):
setattr(self, "test2", test2)
print self.test2
self.test2()
def main():
a = A()
a.test()
if __name__ == '__main__':
main()
This code has no interest and you can't use self in your new method you added. I just found this code fun, but I will never use this. I don't like to dynamicaly change the object itself.
It's the fastest way, and more understandable.