Inheritance question

Anthony anthonysmith80 at
Tue Mar 25 16:31:49 CET 2008

On Mar 25, 2:31 pm, Tzury Bar Yochay <Afro.Syst... at> 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:

class FooSon(Foo):
    def __init__(self): = Foo() = 2
    def getid(self):
        a =
        b =
        return '%d.%d' % (a,b)

>>> FooSon().getid()

Or change "" in Foo to something else, e.g., "self.id_foo".

Does that help?


More information about the Python-list mailing list