T
Thomas Guettler
Hi!
How can I add a method to an object.
This code does not work:
class Foo:
def __init__(self):
self.counter=0
f=Foo()
def incr(self):
self.counter+=1
f.incr=incr
f.incr()
===> python extend.py
Traceback (most recent call last):
File "extend.py", line 12, in ?
f.incr()
TypeError: incr() takes exactly 1 argument (0 given)
How can I add a method to an object.
This code does not work:
class Foo:
def __init__(self):
self.counter=0
f=Foo()
def incr(self):
self.counter+=1
f.incr=incr
f.incr()
===> python extend.py
Traceback (most recent call last):
File "extend.py", line 12, in ?
f.incr()
TypeError: incr() takes exactly 1 argument (0 given)