Created
November 19, 2014 14:14
-
-
Save masak/864795f3af67359d9a9f to your computer and use it in GitHub Desktop.
bound and unbound methods in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python | |
Python 2.7.6 (default, Mar 22 2014, 22:59:56) | |
[GCC 4.8.2] on linux2 | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> class C: | |
... def __init__(self, name): | |
... self.name = name | |
... def foo(self): | |
... print self.name | |
... | |
>>> C.foo | |
<unbound method C.foo> | |
>>> C.foo.__get__(C('arnsholt')) | |
<bound method ?.foo of <__main__.C instance at 0x7f0f5d1037e8>> | |
>>> C.foo.__get__(C('arnsholt'))() | |
arnsholt | |
>>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment