Created
August 25, 2016 21:20
-
-
Save motivic/ee035d1bf589526727c5b0a9b2a8a063 to your computer and use it in GitHub Desktop.
Using super in Python 2.7
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
# http://stackoverflow.com/questions/222877/how-to-use-super-in-python | |
class SomeBaseClass(object): | |
def __init__(self): | |
print('SomeBaseClass.__init__(self) called') | |
class ChildClass(SomeBaseClass): | |
def __init__(self): | |
print('ChildClass.__init__(self) called') | |
SomeBaseClass.__init__(self) | |
class SuperChildClass(SomeBaseClass): | |
def __init__(self): | |
print('SuperChildClass.__init__(self) called') | |
super(SuperChildClass, self).__init__() | |
class InjectMe(SomeBaseClass): | |
def __init__(self): | |
print('InjectMe.__init__(self) called') | |
super(InjectMe, self).__init__() | |
# behavior depends on inheritance order | |
class UnsuperInjector(InjectMe, ChildClass): pass | |
# class UnsuperInjector(ChildClass, InjectMe): pass | |
class SuperInjector(InjectMe, SuperChildClass): pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment