Dynamic class methods misunderstanding
Bill Mill
bill.mill at gmail.com
Fri Jan 28 11:28:54 EST 2005
Kamilche,
On Fri, 28 Jan 2005 08:10:07 -0800 (PST), Kamilche
<klachemin at comcast.net> wrote:
> 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()
>
beautiful; so this appears to be equivalent to the __class__ method
that Hans suggested.
Thanks a lot.
Peace
Bill Mill
bill.mill at gmail.com
> --
> http://mail.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list