Inheritance question

Diez B. Roggisch deets at nospam.web.de
Tue Mar 25 12:08:08 EDT 2008


Anthony wrote:

> On Mar 25, 2:31 pm, Tzury Bar Yochay <Afro.Syst... at gmail.com> wrote:
>> 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().
> 
> I don't think Foo.__init__(self) creates an instance of the Foo
> class.  If you want FooSon to create an instance of Foo, try:

You wrote:

a = Foo().getid()

Which indeed creates a *new* Foo-instance. So it's of no use to the OP.

Of course Foo.<method>(self) calls that method without creating a new
instance, which is the behavior one uses when invoking the constructor of
Foo inside FooSon.__init__. But that doesn't make your example any better.

Diez



More information about the Python-list mailing list