When I do the following:
class C:
pass
def f( self ):
print self
a = C()
a.f = f
a.f()
I get the following error at the line a.f(): TypeError: f() takes exactly 1 argument (0 given)
The problem appears to be that when f is added to the instance, a, it is treated like a function that is stored inside of a, rather than an actual member function. If I change a.f() to a.f(a), then I get the intended effect, but is there a way to make python interpret the original example this way? In other words, is there a way to add a member function to an instance of a class at runtime?
Thanks