I never expected the inheritance of Python 2.7 is so anti-human. Why the following code give me a TypeError?
>>> class P:
... def _
There are two responses possible for your question, according to the version of Python you're using.
super
has to be called like this (example for the doc):
class C(B):
def method(self, arg):
super(C, self).method(arg)
In your code, that would be:
>>> class P(object): # <- super works only with new-class style
... def __init__(self, argp):
... self.pstr=argp
...
>>> class C(P):
... def __init__(self, argp, argc):
... super(C, self).__init__(argp)
... self.cstr=argc
You also don't have to pass self
in argument in this case.
In Python 3.x, the super
method has been improved: you can use it without any parameters (both are optional now). This solution can work too, but with Python 3 and greater only:
>>> class C(P):
... def __init__(self, argp, argc):
... super().__init__(argp)
... self.cstr=argc