Last active
August 29, 2015 14:01
-
-
Save devsli/82e6a6a20d80e5716798 to your computer and use it in GitHub Desktop.
Invoke unbound method
This file contains 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 __init__(self): | |
self.name = 'Andy' | |
def tell(what): | |
def inner(self): | |
print(" -- %s, %s!" % (what, self.name)) | |
return inner | |
hi = tell("Hello") | |
class B(A): | |
def __init__(self): | |
self.name = 'Billy Bob' | |
tell = A.tell.__func__ | |
bye = tell("Bye") | |
class C(object): | |
def __init__(self): | |
self.name = 'Charlie' | |
tell = A.tell.__func__ | |
bye = tell("See ya") | |
A().hi() # -- Hello, Andy! | |
B().bye() # -- Bye, Billy Bob! | |
C().bye() # -- See ya, Charlie! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment