I am trying to call the __init__()
method in a superclass, where said method takes arguments, but it doesn't seem to be working. Please see the code below:
>>> class A:
def __init__(self, param1, param2):
self._var1 = param1
self._var2 = param2
>>> class B(A):
def __init__(self, param1, param2, param3):
super(B, self).__init__(param1, param2)
self._var3 = param3
>>> a = A("Hi", "Bob")
>>> a._var1
'Hi'
>>> a._var2
'Bob'
>>>
>>> b = B("Hello", "There", "Bob")
Traceback (most recent call last):
File "<pyshell#74>", line 1, in <module>
b = B("Hello", "There", "Bob")
File "<pyshell#69>", line 3, in __init__
super(B, self).__init__(param1, param2)
TypeError: must be type, not classobj
>>>
I have never been able to get this to work. What am I doing wrong? I would ideally like to use super()
over A.__init__(self, <parameters>)
, if this is a possibility (which it must be).