why no ++?

Alex Martelli aleaxit at yahoo.com
Sun Aug 19 15:08:43 EDT 2001


"Bernd Nawothnig" <Bernd.Nawothnig at t-online.de> wrote in message
news:slrn9o00r9.3vvk8mr.Bernd.Nawothnig at Asterix.t-online.de...
    ...
> >>>    y.a = b,c,d = x.e = wower()
    ...
> >  First wower is called, then y.a is assigned, then b,c,d, then x.e, in
this
> >  order.  But of course it wouldn't be wise to rely on this!-)
>
> Hmm, without having true symbol-expressions (lvals speaken in C-ish) it
> makes no difference which of the different symbols is bound physically
first
> to a value because there can't be any side effect.

Wrong: binding an _object's attribute_ (or item) can perfectly
well have side effects.

class Tracer:
    def __init__(self,name):
        self.__dict__['name'] = name
    def __setattr__(self,name,value):
        print "bound %s.%s to %s"%(
            self.name, name, value)
        self.__dict__[name] = value

y = Tracer('y')
x = Tracer('x')

def wower():
    print "wower called"
    return 'wow'

y.a = b,c,d = x.e = wower()


D:\MinGw32>python zz.py
wower called
bound y.a to wow
bound x.e to wow


As you can see, it DOES make a perfectly perceptible
difference "which of the different [attributes] is bound
first to a value", even "without having true symbol-
expressions".


Alex






More information about the Python-list mailing list