I'd like to assign different values to inherited attributes in the instances of a child class. The code I use is
class Parent:
def __init__(self, n=50):
# there are multiple parent attributes like 'n'
# I use just one to reproduce the error
self.n = n
def print_n(self):
print('n =', self.n)
class Child(Parent):
def __init__(self, a=5):
self.a = a
def print_a(self):
print('a =', self.a)
son1 = Child(n=100)
son1.print_n()
The error message is
son1 = Child(n=100)
TypeError: __init__() got an unexpected keyword argument 'n'
What would be the correct way to achieve the objective?
I tried to put super().init() in the init method of the child class according to the answer to this similar question, but it didn't work.
Childclass constructor has to call theParentclass constructor.super(Child, self).__init__()