[Tutor] OO newbie

Alan Gauld alan.gauld at freenet.co.uk
Fri Apr 8 12:18:47 CEST 2005


> > super is just a convenience feature added to make Python slightly
> > more like some other OOP languages. It is effectively just a
> > wrapper around the explicit call to the super class:
> >
> > Thus super(C,self...) is the same as
> >
> > dict.__init__(self...)
> after you telling me that dict.__init__(self...) should in your
opinion
> the way to do it.

That's not quite what I said. super has some advantages - it means
you don't need to change code so much if you change the class
heirarchy
and so on. Unfortunately the way super is implemented in Python it
does seem to be less effective in that way than I'd like...

The bottom line is that I *personally* prefer to use explicit calls,
but there is nothing wrong with using super if you find it more
readable.

> type(dict)
> <type 'type'>
> so dict is a class
>
>
> dict.__init__ is the function to initialize a dictionnary
> so
> dict.__init__(self...) initialize the dictionnary `self'. Which work
> because self derive from a dictionnary...
>
> I got it !

Well done. Sometimes you just have to churn the ideas around for
a while until the light comes on.

> I was really lost because I was not clearly making a difference
between
> the class: ``dict'' and an instance of it: ``dict()''

Yes, it might help if Python had used the capitalised name convention
for types, but that was settled a long time before the builtin types
became classes (in v2.2?) so we have to live with the confusion...

Alan G.



More information about the Tutor mailing list