Inheritance question

Tzury Bar Yochay Afro.Systems at gmail.com
Tue Mar 25 10:31:06 EDT 2008


On Mar 25, 4:03 pm, Anthony <anthonysmit... at gmail.com> wrote:
> On Mar 25, 11:44 am, Tzury Bar Yochay <Afro.Syst... at gmail.com> wrote:
>
> > 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
>
> Is this what you want?
>
> 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)
>
> >>> FooSon().getid()
>
> '1.2'
>
> Best wishes,
> Anthony

I wish it was that simple but 'a = Foo().getid()' is actually creating
a new instance of Foo whereas I want the data of the Foo instanced by
__init__ of FooSon().

what I am actually trying to do is to build a set of classes which
handle different type of binary messages coming from the network.

a base message which handles its basic data parts (src, dst, etc.) and
extending it per message type. thus I looked for a way to get the
child calling super for parsing the super's prats and then having the
child parsing its additional details.




More information about the Python-list mailing list