Inheritance And Instantiation Of Instance Variables

maney at pobox.com maney at pobox.com
Sat Nov 23 22:17:53 EST 2002


Ben C <b.e.n.c.a.t.7.3. at .t.p.g...c.o.m...a.u> wrote:
> if I create a class such as
> 
> class Blah:
>    def __init__(self, parameterA, parameterB)
>        self.parameterA = parameterA
>        self.parameterB = parameterB
> 
> and then I inherit from that class is it really necessary to initialise the
> argumnets to the inherited class twice ? ie.
> 
> class NewBlah(Blah):
> 
>    def __init__(self, parameterA, parameterB)
>        Blah.__init__(self, parameterA, parameterB)

It certainly isn't necessary to initialize them twice, but your NewBlah
constructor isn't doing that the way you show it here.  Python doesn't
magically invoke base class methods, not even constructor methods, so
you can initialize things once by invoking the base constructor or by
rolling your own initialization code.  Or you can leave the class an
empty husk and figure out how to make that work, if it's worthwhile to
make intialization lazy.



More information about the Python-list mailing list