replacement for new.instancemethod in Python3?

Michele Simionato michele.simionato at gmail.com
Sun Apr 5 14:13:07 CEST 2009


On Apr 5, 2:02 pm, s... at pobox.com wrote:
> Is there a replacement in Python3 for new.instancemethod?  That is, given an
> arbitrary instance (not its class) how can I add a new appropriately defined
> function as a method to it?

There is no need for new.instancemethod for new style classes:

>>> class C: pass
...
>>> c=C()
>>> def f(self): pass
...
>>> c.f = f.__get__(c, C)
>>> c.f
<bound method C.f of <__main__.C object at 0xb7b6fdec>>



More information about the Python-list mailing list