total idiot question: +=, .=, etc...

Michael Hudson mwh21 at cam.ac.uk
Fri Jun 25 03:08:00 EDT 1999


neelk at brick.cswv.com (Neel Krishnaswami) writes:

> 
> It's just that writing self.__class__ is so *ugly*! Everything else
> in Python is beautiful, too, which makes this stand out even more. 
>  

You want ugly? I think the whole area of calling base class functions
is far uglier.

You might have a base class like this:

class C:
    def f(self,x):
        print self

then a derived class that needed to call C.f would have to be written:

class D(C):
    def f(self,x):
        C.f(self,x)
        print x

I think needing `self' here sucks. It gets worse if there are keyword
arguments, necessitating use of apply, or if the base class is in a
different module.

This can be combined with another irritation of mine, the lack of
automatic initialization of base classes, to give a situation like
this:

base.py:

class Base:
    def __init__(self,x,y,**kw):
         ...

derived.py:

import base

class Derived(base.Base):
    def __init__(self,x,y,z,**kw):
        apply(base.Base.__init__,(self,x,y),kw)
        print z

which I think is one of the ugliest things I've ever seen in Python
that I couldn't think of a prettier way round. Ideas, anyone?

twisted-ly y'rs
Michael




More information about the Python-list mailing list