Skip to content

Instantly share code, notes, and snippets.

@binki
Created March 8, 2016 05:03
Show Gist options
  • Save binki/3e1305623bed138b6033 to your computer and use it in GitHub Desktop.
Save binki/3e1305623bed138b6033 to your computer and use it in GitHub Desktop.
Python is less like JavaScript in handling the dot operator than I thought
>>> def callCallback(cb):
... cb()
...
>>> class MyClass(object):
... def __init__(self, x):
... self.x = x
... def f(self):
... print('x = %s' % (self.x, ))
...
>>> myObject = MyClass(3)
>>> myObject.f()
x = 3
>>> callCallback(myObject.f)
x = 3
>>> y = myObject.f
>>> y()
x = 3
>>> id(myObject.f)
139765962147240
>>> id(MyClass.f)
139765961293696
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment