Inheritance question
Furkan Kuru
furkankuru at gmail.com
Tue Mar 25 08:48:03 EDT 2008
a = super(Foo, self).getid()
should be
a = super(FooSon, self).getid()
On Tue, Mar 25, 2008 at 2:34 PM, Tzury Bar Yochay <Afro.Systems at gmail.com>
wrote:
> > Rather than use Foo.bar(), use this syntax to call methods of the
> > super class:
> >
> > super(ParentClass, self).method()
>
> Hi Jeff,
> here is the nw version which cause an error
>
> class Foo(object):
> def __init__(self):
> self.id = 1
>
> def getid(self):
> return self.id
>
> class FooSon(Foo):
> def __init__(self):
> Foo.__init__(self)
> self.id = 2
>
> def getid(self):
> a = super(Foo, self).getid()
> b = self.id
> return '%d.%d' % (a,b)
>
>
> FooSon().getid()
>
>
> Traceback (most recent call last):
> File "a.py", line 19, in <module>
> FooSon().getid()
> File "a.py", line 14, in getid
> a = super(Foo, self).getid()
> AttributeError: 'super' object has no attribute 'getid'
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
Furkan Kuru
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080325/9a4666a6/attachment-0001.html>
More information about the Python-list
mailing list