Inheritance question

Furkan Kuru furkankuru at gmail.com
Tue Mar 25 08:51:30 EDT 2008


In the derived class init you set self.id to 2 so
when you call getid method it just returns self.id which is now 2.
you can use another variable name.

On Tue, Mar 25, 2008 at 1:44 PM, Tzury Bar Yochay <Afro.Systems at gmail.com>
wrote:

> given two classes:
>
> 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 = Foo.getid()
>        b = self.id
>        return '%d.%d' % (a,b)
>
> While my intention is to get 1.2 I get 2.2
> I would like to know what would be the right way to yield the expected
> results
> --
> 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/5218f67e/attachment-0001.html>


More information about the Python-list mailing list