Last active
August 29, 2015 14:00
-
-
Save ranchodeluxe/11195555 to your computer and use it in GitHub Desktop.
i like python that acts like javascript
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
class A( object ): | |
def bang(self): | |
print "bang" | |
print "self => %s" % self | |
return True | |
class B( object ): | |
pass | |
if __name__ == '__main__': | |
b = B() | |
unbound_func = getattr( A, 'bang' ) | |
print unbound_func | |
bound_func = unbound_func.__get__( b, A ) | |
print bound_func | |
print bound_func() | |
-----------OUTPUT------------------ | |
<unbound method A.bang> | |
<bound method A.bang of <__main__.B object at 0x213fcd0>> | |
bang | |
self => <__main__.B object at 0x213fcd0> | |
True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Starring, as the change from "go" --> "bang" makes this example much more clear to the end-user ;)