Created
October 9, 2017 01:43
-
-
Save pmdarrow/ab0baac3473f30be331f5da8645ef562 to your computer and use it in GitHub Desktop.
Python inheritance
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 Base(object): | |
def __init__(self, foo='foo_text', bar='bar_text'): | |
self.foo = foo | |
self.bar = bar | |
class Child(Base): | |
def __init__(self, extra='extra_text', *arg, **kwargs): | |
self.extra = extra | |
super(Child, self).__init__(*arg, **kwargs) | |
class OtherChild(Base): | |
def __init__(self, foo='OtherChild preset', *arg, **kwargs): | |
foo_value = foo.upper() | |
super(OtherChild, self).__init__(foo=foo_value, *arg, **kwargs) | |
if __name__ == '__main__': | |
c = OtherChild() | |
print(c.__dict__) | |
def myfunc(*args, **kwargs): | |
print(args, kwargs) | |
myfunc('arg1', arg2='arg2') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment