'TypeError: __init__() got multiple values for argument' with Python 3 using super() function

'TypeError: __init__() got multiple values for argument' with Python 3 using super() function

我正在 Python 3 中编写带有继承的 OOP 程序,当我尝试像这样初始化 child class 时 运行 进入标题错误:

class Parent:
    def __init__(self, var1, var2):
        self.var1 = var1
        self.var2 = var2

    #more methods that to some stuff

class Child(Parent):
    a = 1 #a and b are class attributes
    b = 2

    def __init__(self, var1 = 1, var2 = 2, var3 = None):
        super().__init__(self, var1 = 1, var2 = 2) #error shows up for this line
        self.var3 = var3

child_obj = Child(var3 = 3)

当我创建 Child object 时,我收到一条错误消息:TypeError: __init__() got multiple values for argument 'var1'。任何人都知道这里可能出了什么问题?提前致谢。

请检查您的代码是否有误。 你想要这样的东西吗?

class Parent:
    def __init__(self, var1, var2):
        self.var1 = var1
        self.var2 = var2
        print(var2)

    #more methods that to some stuff

class Child(Parent):
    a = 1 #a and b are class attributes
    b = 2

    def __init__(self, var1 = 1, var2 = 2, var3 = None):
        super().__init__(var1 = 1, var2 = 2) 
        self.var3 = var3

child_obj = Child(var3 = 3)