[Tutor] Importing modules/classes

Jacob S. keridee at jayco.net
Fri Sep 16 03:27:23 CEST 2005


> You need to call the init method of the inherited class(es) from
> within your init. It's conventional to call the superclass
> constructor
> before doing your own initialisation so it should look like:
>
>    def __init__(self, num):
>        Thread.__init__(self)
>        print "__init__: Num = ", num
>
> There is a new technique for doing this in recent Python version
> (v2.2 onwards?) using the super keyword, but I've still to get
> my own head around it... :-)

super isn't a keyword, but a builtin function.
usage:

super(self).__init__()

It was mentioned on the list a couple of months ago, and as I gathered,
it didn't come out in favor of super() do to the fact that if a user-defined
class inherits from more than one class, super only calls one of the 
classes,
or something like that.  Perhaps it's better just to call them explicitly.

Jacob 



More information about the Tutor mailing list