简体   繁体   中英

Error: TypeError: __init__() takes 1 positional argument but 2 were given

I am an absolutely Python beginner and don't understand the problem of the following lines.

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()

I think super calls looking from C init in the following order: AB-Base-Base or am I wrong?

Thank you for your answers.

Use the below code:

class A(Base):
    def __init__(self):
        super(A, self).__init__() #Remove this 1
        print("A")

I hope it may help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM