I am writing an OOP program in Python 3 with inheritance and am running into the title error when I try to initialize the child class like so:
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)
When I create a Child
object I get an error saying: TypeError: __init__() got multiple values for argument 'var1'
. Anyone know what could be wrong here? Thanks in advance.
Please check your code it's wrong. You want somthing like this?
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)