Error: TypeError: __init__() takes 1 positional argument but 2 were given
Error: TypeError: __init__() takes 1 positional argument but 2 were given
我绝对是Python初学者,不明白下面几行的问题。
class Base:
def __init__(self, x):
print("Base")
self.x = x
class A(Base):
def __init__(self):
super(A, self).__init__(1)
print("A")
class B(Base):
def __init__(self):
super(B, self).__init__(2)
print("B")
class C(A, B):
def __init__(self):
super(C, self).__init__()
print("C")
if __name__ == '__main__':
c = C()
我认为从 C init 中查找超级调用的顺序如下:A-B-Base-Base 还是我错了?
感谢您的回答。
使用下面的代码:
class A(Base):
def __init__(self):
super(A, self).__init__() #Remove this 1
print("A")
希望对你有所帮助
我绝对是Python初学者,不明白下面几行的问题。
class Base:
def __init__(self, x):
print("Base")
self.x = x
class A(Base):
def __init__(self):
super(A, self).__init__(1)
print("A")
class B(Base):
def __init__(self):
super(B, self).__init__(2)
print("B")
class C(A, B):
def __init__(self):
super(C, self).__init__()
print("C")
if __name__ == '__main__':
c = C()
我认为从 C init 中查找超级调用的顺序如下:A-B-Base-Base 还是我错了?
感谢您的回答。
使用下面的代码:
class A(Base):
def __init__(self):
super(A, self).__init__() #Remove this 1
print("A")
希望对你有所帮助