Let’s say, I have the following two classes:
class A(object):
def __init__(self, i):
self.i = i
class B(object):
def __init__(self, j):
self.j = j
class C(A, B):
def __init__(self):
super(C, self).__init__(self, 4)
c = C()
c will only have the i attribute set, not the j.
What should I write to set both of attributes/only the j attribute?
If you want to set only the
jattribute, then only callB.__init__:If you want to manually call both
AandB‘s__init__methods, thenof course you could do this:
Using
superis a bit tricky (in particular, see the section entitled “Argument passing, argh!”). If you still want to usesuper, here is one way you could do it: