[Tutor] super() and inherited attributes?
magoldfish at gmail.com
Tue Jun 28 06:58:41 CEST 2005
The following example doesn't work as I would like-- the child
instance doesn't expose the attribute set in the parent. Can someone
point out what I am missing?
def __init__(self, name="I am a parent"):
self.name = name
def __init__(self, number):
super(Parent, self).__init__("I am a child")
self.number = number
# I would like it to produce the following:
>> c = Child(23)
"I am a child"
# but I 'AttributeError: 'Child' object has no attribute 'name''
More information about the Tutor