[Tutor] super() and inherited attributes?
Marcus Goldfish
magoldfish at gmail.com
Tue Jun 28 06:58:41 CEST 2005
Hi,
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?
Thanks,
Marcus
class Parent(object):
def __init__(self, name="I am a parent"):
self.name = name
class Child(Parent):
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)
>> c.number
23
>> c.name
"I am a child"
# but I 'AttributeError: 'Child' object has no attribute 'name''
More information about the Tutor
mailing list