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

Alexander Williams thantos at brimstone.mecha
Wed Jun 23 23:25:28 EDT 1999


On 23 Jun 1999 20:56:41 -0500, Neel Krishnaswami <neelk at brick.cswv.com> 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
9
>>> y.setX(12)
>>> y.x
12

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 gw.total-web.net)
"In the end ... Oblivion Always Wins."




More information about the Python-list mailing list