Hello,
I want to replace a method in a class during run-time with another function. I tried
the obvious, but it didn't work:
class This(object):
def update(self,val ):
print val
def another_update( obj,val):
print "another",v al
t=This()
t.update(5)
t.update=anothe r_update
t.update(5) # this one doesn't work, gives
# TypeError: another_update( ) takes exactly 2 arguments (1 given)
clearly it isn't seeing it as a method, just an attribute which happens to be a
function. Is there a preferred way to do this?
thanks,
Brian Blais
--
-----------------
bblais@bryant.e du
I want to replace a method in a class during run-time with another function. I tried
the obvious, but it didn't work:
class This(object):
def update(self,val ):
print val
def another_update( obj,val):
print "another",v al
t=This()
t.update(5)
t.update=anothe r_update
t.update(5) # this one doesn't work, gives
# TypeError: another_update( ) takes exactly 2 arguments (1 given)
clearly it isn't seeing it as a method, just an attribute which happens to be a
function. Is there a preferred way to do this?
thanks,
Brian Blais
--
-----------------
bblais@bryant.e du
Comment