super - is (should) it (be) a reserved word?
Alan Gauld
alan.gauld at gssec.bt.co.uk
Wed Oct 11 08:56:26 EDT 2000
Alan Gauld wrote:
> 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:
But Jay.Krell responded:
> Sorry, no, that doesn't work. Python is too dynamic.
>
> class Food:
> def Print(self):
> print("Food")
>
> class Dessert(Food):
> super = Food
> def Print(self):
> self.super.Print(self)
> print("Dessert")
>
> class Pie(Dessert):
> super = Dessert
> def Print(self):
> self.super.Print(self)
> print("Pie")
>
> Pie().Print();
>
> recurses infinitely. You were just lucky to try with only two
Which is of course true because self always points to the
leaf node....oops!
Back to the drawing board I guess :-)
> 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.
Which is still an issue I'fd like to see a solution for.
Alan G
--
=================================================
This post represents the views of the author
and does not necessarily accurately represent
the views of BT.
More information about the Python-list
mailing list