[Tutor] bound vs. unbound method?
Pijus Virketis
virketis@fas.harvard.edu
Wed, 21 Nov 2001 10:24:54 -0500
--=====================_127577535==_.ALT
Content-Type: text/plain; charset="us-ascii"
Hi!
I found a brief mention of bound and unbound methods in Python on
comp.lang.python archives. What is the difference between the two? Here's a
piece of the original message:
******************************* Erik Max Francis wrote *********************
It [Python - added by me] even has both bound and unbound methods, something
which, for instance, C++ does not have:
>>> class C:
... def m(self, x):
... print x
...
>>> c = C()
>>> unbound = C.m
>>> unbound(c, 1) # must call with `self' argument explicitly 1
>>> bound = c.m
>>> bound(1) # `self' argument implied, not needed 1
****************************************************************************
****
I don't know C++, so the distinction is sort of lost on me. :(
Cheers,
Pijus
------------------------------------------------------------
PGP PUBLIC KEY: www.fas.harvard.edu/~virketis/links
My weblog: www.fas.harvard.edu/~virketis
--=====================_127577535==_.ALT
Content-Type: text/html; charset="us-ascii"
<html>
Hi!<br>
<br>
I found a brief mention of bound and unbound methods in Python on
comp.lang.python archives. What is the difference between the two? Here's
a piece of the original message:<br>
<br>
******************************* Erik Max Francis wrote
*********************<br>
<br>
It [Python - added by me] even has both bound and unbound methods,
something which, for instance, C++ does not have: <br>
<br>
<font color="#800000">>>> class C:</font><font color="#000000">
<br>
... def m(self, x): <br>
... print x <br>
... <br>
</font><font color="#800000">>>> c = C() <br>
>>> unbound = C.m <br>
>>> unbound(c, 1) # must call with `self' argument explicitly 1 <br>
>>> bound = c.m <br>
>>> bound(1) # `self' argument implied, not needed</font><font color="#000000"> 1 <br>
<br>
********************************************************************************<br>
<br>
I don't know C++, so the distinction is sort of lost on me. :(<br>
<br>
Cheers, <br>
<br>
Pijus</font><br>
<div>------------------------------------------------------------</div>
<div>PGP PUBLIC KEY: <a href="http://www.fas.harvard.edu/~virketis/links" EUDORA=AUTOURL>www.fas.harvard.edu/~virketis/links</a></div>
<div>My weblog: <a href="http://www.fas.harvard.edu/~virketis" EUDORA=AUTOURL>www.fas.harvard.edu/~virketis</a></div>
</html>
--=====================_127577535==_.ALT--