Skip to content

Instantly share code, notes, and snippets.

@masak
Created November 19, 2014 14:14
Show Gist options
  • Save masak/864795f3af67359d9a9f to your computer and use it in GitHub Desktop.
Save masak/864795f3af67359d9a9f to your computer and use it in GitHub Desktop.
bound and unbound methods in Python
$ 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