In the code:
class Mother(object):
def __init__(self):
self._haircolor = "Brown"
class Child(Mother):
def __init__(self):
#Mother.__init__(self)
super(Mother, self).__init__(self)
def print_haircolor(self):
print self._haircolor
c = Child()
c.print_haircolor()
Why does Mother.__init__(self)
work fine (it outputs Brown
), but super(Mother, self).__init__(self)
give the error
Traceback (most recent call last):
File "test2.py", line 13, in <module>
c = Child()
File "test2.py", line 8, in __init__
super(Mother, self).__init__(self)
TypeError: object.__init__() takes no parameters
I've seen this, this, this and this, but it doesn't answer the question.