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

Alexander Williams thantos at brimstone.mecha
Thu Jun 24 05:25:28 CEST 1999

On 23 Jun 1999 20:56:41 -0500, Neel Krishnaswami <neelk at> wrote:
>It's just that writing self.__class__ is so *ugly*! Everything else
>in Python is beautiful, too, which makes this stand out even more. 

Er, that could be because you're doing it wrong?  Try:

class Foo:
    def __init__(me):
        me.x = 9

    def setX(me, val):
        me.x = val

>>> y = Foo()
>>> y.x
>>> y.setX(12)
>>> y.x

If you /really/ want to go frobbing around with the value that all
instances of the class inherit from, instance.__class__.slot is likely
a /great/ way of pointing out to the reader you're doing something
funky (in that classes are usually thought of as immutable, despite
the reality).  The 'unsightly' nature of the construct makes it clear
you're doing something unasthetic.

Alexander Williams (thantos at
"In the end ... Oblivion Always Wins."

More information about the Python-list mailing list