Python's super() considered super!

sturlamolden sturlamolden at yahoo.no
Fri May 27 10:27:53 EDT 2011


On 26 Mai, 18:31, Raymond Hettinger <pyt... at rcn.com> wrote:
> I just posted a tutorial and how-to guide for making effective use of
> super().
>
> One of the reviewers, David Beazley, said, "Wow,  that's really
> great!    I see this becoming the definitive post on the subject"
>
> The direct link is:
>
>  http://rhettinger.wordpress.com/2011/05/26/super-considered-super/

I really don't like the Python 2 syntax of super, as it violates
the DRY principle: Why do I need to write super(type(self),self)
when super() will do? Assuming that 'self' will always be named
'self' in my code, I tend to patch __builtins__.super like this:

import sys
def super():
    self = sys._getframe().f_back.f_locals['self']
    return __builtins__.super(type(self),self)

This way the nice Python 3.x syntax can be used in Python 2.x.


Sturla









More information about the Python-list mailing list