Skip to content

Instantly share code, notes, and snippets.

@broqdev
Last active December 10, 2015 12:18
Show Gist options
  • Save broqdev/4433729 to your computer and use it in GitHub Desktop.
Save broqdev/4433729 to your computer and use it in GitHub Desktop.
how to call derived method in parent class
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