Last active
December 10, 2015 12:18
-
-
Save broqdev/4433729 to your computer and use it in GitHub Desktop.
how to call derived method in parent class
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 Foo(object): | |
| def __init__(self): | |
| self._func = None | |
| def callDerivedFunc(self): | |
| # self._func() # call bound method | |
| # self._func(self) # call unbound method | |
| method = self._func | |
| method(self) # call unbound method | |
| class Bar(Foo): | |
| def __init__(self): | |
| super(Foo, self).__init__() | |
| self._func = Bar.hello # unbound method | |
| # self._func = self.hello # bund method | |
| def hello(self): | |
| print 'Hello' | |
| bar = Bar() | |
| bar.callDerivedFunc() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment