This is strange, but you can use __slots__ to achieve this:
class Base(object): def __init__(self, *args, **kw): for k,v in zip(self.__slots__, args): setattr(self, k, v) for k,v in kw.items(): setattr(self, k, v) class ChildA(Base): __slots__ = 'a', 'b', 'c' class ChildB(Base): __slots__ = 'x', 'y', 'z'
You can also use the following technique to save yourself on typing when initializing classes with many arguments:
def autoargs(l): self = l.pop('self') for k,v in l.items(): setattr(self, k, v) class Base(object): def __init__(self, a, b, c): autoargs(locals())
I hope I understand your question correctly.
source share