passing methods/functions

Stefan Franke spamfranke at bigfoot.de
Sun May 7 20:47:24 CEST 2000


On Sun, 07 May 2000 07:29:48 GMT, Courageous <jkraska1 at san.rr.com>
wrote:

>
>Passing around "pointers to functions" is something I intrinsically
>understand, but if an instance of an object passes a reference to
>one of its methods, how does python keep track of the instance?

A "bound method" basically keeps a pair of references - to the method
and the instance:

>>> class C: pass
>>> class C:
... 	def a(): pass
>>> C.a
<unbound method C.a>
>>> C().a
<method C.a of C instance at 1a20e10>


Stefan




More information about the Python-list mailing list