I have a base class with a lot of __init__
arguments:
class BaseClass(object):
def __init__(self, a, b, c, d, e, f, ...):
self._a=a+b
self._b=b if b else a
...
All the inheriting classes should run __init__
method of the base class.
I can write a __init__()
method in each of the inheriting classes that would call the superclass __init__
, but that would be a serious code duplication:
class A(BaseClass):
def __init__(self, a, b, c, d, e, f, ...):
super(A, self).__init__(a, b, c, d, e, f, ...)
class B(BaseClass):
def __init__(self, a, b, c, d, e, f, ...):
super(A, self).__init__(a, b, c, d, e, f, ...)
class C(BaseClass):
def __init__(self, a, b, c, d, e, f, ...):
super(A, self).__init__(a, b, c, d, e, f, ...)
...
What's the most Pythonic way to automatically call the superclass __init__
?
super(SubClass, self).__init__(...)
Consider using *args and **kw if it helps solving your variable nightmare.