Re:Metaclasses in Python
by storborg on Thursday December 15, 2011 @01:33PM
(#3357305)
Use types.MethodType for that:
Edit: pre-2.6 you'd use "new.instancemethod()"
[ Parent
| on HN ]
Yes, or alternatively I believe
In [27]: class Foo(object):
....: pass
....:
In [28]: def hello(self):
....: print self
....:
In [29]: blah = Foo()
In [30]: blah.hello = hello.__get__(blah, Foo)
In [31]: blah.hello()
<__main__.Foo object at 0x10397f650>