Kylotan wrote:[color=blue]
>
> Although I see lots of references to them in various documentation, I
> can't find a decent explanation of exactly what they are. I'm guessing
> that it's a reference to a method that remembers which object it came
> from, and that when it's called, it passes that object as the first
> parameter (which would conventionally be 'self'). Is this correct?[/color]
Yep:
[color=blue][color=green][color=darkred]
>>> class C:[/color][/color][/color]
.... def f(self, x):
.... print x
....[color=blue][color=green][color=darkred]
>>> c = C() # c is an instance of C
>>> C[/color][/color][/color]
<class __main__.C at 0x402e141c>[color=blue][color=green][color=darkred]
>>> C.f # the unbound method[/color][/color][/color]
<unbound method C.f>[color=blue][color=green][color=darkred]
>>> c.f # the bound method[/color][/color][/color]
<bound method C.f of <__main__.C instance at 0x402e4c8c>>[color=blue][color=green][color=darkred]
>>> C.f(c, 1) # invoking unbound methods requires passing the instance[/color][/color][/color]
1[color=blue][color=green][color=darkred]
>>> c.f(1) # bound methods already contain the instance[/color][/color][/color]
1
--
Erik Max Francis &&
max@alcyone.com &&
http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \
\__/ There are defeats more triumphant than victories.
-- Montaigne