Mike C. Fletcher
mcfletch at rogers.com
Tue Oct 1 21:11:21 CEST 2002
super is a new feature in Python 2.2, it was created to make it possible
to have mix-in classes where you don't _know_ what the super-class is.
It also avoids some errors/maintenance work where base-classes changed
names so that the sub-classes suddenly generated NameErrors.
That said, it's only available in Python 2.2 and above, and although
Python 2.2.x is the target for the current "stable" Python, it's not
universally adopted yet, so code using super will not work on every
Python installation (i.e. it won't work on Python 1.5.2 or 2.1).
So, yes, it's better from a theoretical standpoint (it encodes the
meaning of the call (call my super-class' method) explicitly ("explicit
is better than implicit")), but in practical terms, if you are writing
libraries that need to be backward compatible with old Pythons, then the
explicit class-name approach is better.
Also note, a number of people advocated the following approach with
class B( A ):
_super_b = A.b
_super_a = A.a
def b( self ):
return self._super_b() + 'C'
Which is more up-front work, but does make the inheritance and
overloading of methods explicit in the code, which some people like :) .
Personally, I've just moved to Python 2.2 for everything save PyOpenGL
and SimpleParse and if people need to use the other modules, they need
to upgrade, which lets me use all the neat 2.2 features :) .
> btw. "super(C,self).__init__()" is better than "A.__init(self)"?
> or simply has the adventage that you don't have to specify the
> thanks again,
More information about the Python-list