Search code examples
pythoninheritancetypeerrorparent

Python TypeError inheritance


First, sorry if the question seems to be similar to some previously raised issues; but they didn't help me.I'm trying to use a parent class within a child one. Both classes receive the same input as below:

The parent (PA.py):

class The_Parent():
    def __init__(self,in1=None,in2=None,in3=None):
#
# and the rest of codes ...

And the child (CH.py):

class The_Child(The_Parent)
    def __init__(self,in1,in2,in3):
       The_Parent.__init__(self,in1,in2,in3)
#
#
# the rest of code ...

And now, the main function:

# import requirements and assigning the variables (in1, in2, and in3)
# 
obj = CH.The_Child(in1,in2,in3)
#
#

And the error I got:

TypeError: The_Child() takes 1 positional argument but 3 were given

Just a point, both child and parent should receive the same variables...


Solution

  • If you are trying to call Parent constructor, you can call it using "super" keyword of Python, for more reference you can follow following link: How to invoke the super constructor?