-
-
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
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
>>> 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