Skip to content

Instantly share code, notes, and snippets.

@pmdarrow
Created October 9, 2017 01:43
Show Gist options
  • Save pmdarrow/ab0baac3473f30be331f5da8645ef562 to your computer and use it in GitHub Desktop.
Save pmdarrow/ab0baac3473f30be331f5da8645ef562 to your computer and use it in GitHub Desktop.
Python inheritance
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