Dynamic class methods misunderstanding

Kamilche klachemin at comcast.net
Fri Jan 28 11:08:12 EST 2005


I see what you're attempting to do. However, your code, if it DID run,
would result in a method being added to the object, not the object's
class! Modify the class itself, not the object, as follows:

|class Test:
|    def __init__(self):
|        self.method()
|
|def m(self):
|    print self
|
|setattr(Test, 'method', m)
|Test()




More information about the Python-list mailing list