I have a base class with a lot of __init__ arguments:
def 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:
def A(BaseClass):
def __init__(self, a, b, c, d, e, f, ...):
super(A, self).__init__(a, b, c, d, e, f, ...)
def B(BaseClass):
def __init__(self, a, b, c, d, e, f, ...):
super(A, self).__init__(a, b, c, d, e, f, ...)
def 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.