Adding method to object
Thomas Guettler
guettli at thomas-guettler.de
Wed Dec 3 04:44:12 EST 2003
More information about the Python-list mailing list
Wed Dec 3 04:44:12 EST 2003
- Previous message (by thread): Adding method to object
- Next message (by thread): Adding method to object
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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)
- Previous message (by thread): Adding method to object
- Next message (by thread): Adding method to object
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list