calling upper constructor

Peter Hansen peter at engcorp.com
Thu Jan 31 23:39:57 EST 2002


Yura Ushakhow wrote:
> 
> What do you do to call __init__ of an upper class?
> Like
> 
> class base:
>    def __init__(self):
>      a = 1
> class abc(base):
>    def __init__(self):
>      # how do I call base's init here?

Try this:
        base.__init__(self)

By the way, if you're just starting out, I'll point out
a possible mistake in the above.  If you expected "a = 1"
to create a variable inside the instance created,
you'll find it won't work.  You need to use "self.a = 1"
or you'll just be making a useless local variable.

> Couldn't find it in the docs..

Neither could I, with a few minutes searching.  Curious.

-Peter



More information about the Python-list mailing list