What is wrong with below python inheritance code?

I am using python 3.4. Below is the exception I am getting-

Traceback (most recent call last):
  File "./oop.py", line 20, in <module>
    y = DerivedClass("Manu")
  File "./oop.py", line 15, in __init__
    super().__init__(self,value)
TypeError: __init__() takes 2 positional arguments but 3 were given
class Test:
    class_var = 100   # class attribute
    x = "Anu"            # class attributes

    def __init__(self,value):
        self.value = value

    def normal_function(self):
        return self.value

class DerivedClass(Test):
    def __init__(self,value):
        super().__init__(self,value)    #inheriting base class constructor
        print(self.value*2)

if __name__ == "__main__":
    test_obj = Test("Priya")

Hi,

You must not give self in super().__init__(self,value) .

So super().__init__(value) .

1 Like

just learnt below so updating here -

super().__init__(value)  -- when using super(), no need to pass self

Test.__init__(self,value)   -- when using BaseClassName, one needs to pass self too
2 Likes