If we have class A
, defined as follows,
class A:
def __init__(self, x):
self.x = x
why do most people use
class B(A):
def __init__(self, x, y):
super().__init__(x)
self.y = y
instead of
class B(A):
def __init__(self, x, y):
A.__init__(self, x)
self.y = y
? I think A.__init__(self, x)
is better then super().__init__(x)
because it supports multiple inheritance (and I didn't find a way to do it with super()
):
class A:
def __init__(self, x):
self.x = x
class B:
def __init__(self, y):
self.y = y
class C(A, B):
def __init__(self, x, y, z):
A.__init__(self, x)
B.__init__(self, y)
self.z = z
When I try to use super()
in the previous example, like this:
class A:
def __init__(self, x):
self.x = x
class B:
def __init__(self, y):
self.y = y
class C(A, B):
def __init__(self, x, y, z):
super().__init__(self, x)
super().__init__(self, y)
self.z = z
class C
doesn't have attribute y
(try: c = C(1, 2, 3)
and print(c.y)
in next line).
What am I doing wrong?