super - is (should) it (be) a reserved word?
Alan Gauld
alan.gauld at gssec.bt.co.uk
Wed Oct 11 06:05:25 EDT 2000
Grant Edwards wrote:
> >Wouldn't it be nice if "super" were a reserved word
OK, Having read the thread so far it looks like no-one
has suggested the C++ trick mentioned by Bjarne Stroustrup
in his 'Design and Evolution' book, so here goes:
class Foo:
def __init__(self):
self.a = 1
def doit(self):
print "a = ", self.a
class Bar(Foo):
super = Foo
def __init__(self,n):
self.super.__init__(self)
self.b = n
def doit(self):
self.super.doit(self)
print "b = ", self.b
f = Foo()
f.doit()
b = Bar(5)
b.doit()
This is somewhat like using super and has the real maintenance
advantage that if the superclass of Bar is changed you don't
need to edit all the methods.
Alan G
More information about the Python-list
mailing list