super - is (should) it (be) a reserved word?

Grant Edwards ge at nowhere.none
Mon Oct 9 13:54:26 EDT 2000


In article <mailman.971107340.4022.python-list at python.org>, Michal Wallace wrote:

>> >Why do you need that? Calling a method of a class climbs the
>> >hierarchy for you, all the way up to where the method was first
>> >defined or last overridden.
>> 
>> The example I most often run into is in an __init__ method
>> where I want to initialize the features my subclass is adding
>> and then pass control and the remaining arguments on up to the
>> __init__ method one layer up.  The "super" that I want access
>> to is the parent of the class containing the reference to
>> "super", not the parent of the class of "self".
>
>I see. I was thinking that .super would be a class member, not
>an instance member.

Ah yes.  Good plan.

>you could also call it __super and then you don't have to put
>the classnames in the __init__ (because python does it for you
>for variables starting with [and not ending with] double
>underscores):
>
>class BananaCremePie(Pie):
>    __super = Pie
>    def __init__(self):
>        print "banana creme pie is a..."
>        self.__super.__init__(self)

By Jove, I think he's got it!  That's pretty much what I had in
mind.  Having the current class name scattered around in its
implementation is just as bad has having the parent class name
scattered around: way too much explicit linkage. Too much
required editing (that I undoubtedly screw up) when I cut/paste
a chunk of code from one place to another.

Now the Class name only exists in two lines of code, and
they're right next to each other.  Now I've got a fair chance
of copying the source for the class, editing the bits where I
want functionality to be different, and having it work.

I'd gotten used to thinking of the leading underscores as a way
to hide things from users of a class, and I'd forgotten that it
could also be used as a way to automatically generate (and
reference) class-qualified names.  Darned clever, that.

-- 
Grant Edwards                   grante             Yow!  I want to dress you
                                  at               up as TALLULAH BANKHEAD and
                               visi.com            cover you with VASELINE and
                                                   WHEAT THINS...



More information about the Python-list mailing list