Python 3000 idea: reversing the order of chained assignments
Terry Reedy
tjreedy at udel.edu
Thu Mar 22 01:51:31 EDT 2007
"Mark T" <nospam at nospam.com> wrote in message
news:DvGdnQacTuMlmp_bnZ2dnUVZ_uWdnZ2d at comcast.com...
| This is interesting:
|
| >>> class Test(object):
| ... def __getattribute__(self,n):
| ... print 'reading',n
| ... return object.__getattribute__(self,n)
| ... def __setattr__(self,n,v):
| ... print 'writing',n,v
| ... return object.__setattr__(self,n,v)
| ...
| >>> x=Test()
| >>> x.a=1; x.b=2; x.c=3
| writing a 1
| writing b 2
| writing c 3
| >>> x.a=x.b=x.c
| reading c
| writing a 3
| writing b 3
| >>>
|
| I wouldn't have expected "a" to be assigned first in a right-to-left
parsing
| order. The result is the same in any case.
The assignment order is specified in the language reference.
But many never read and those who do can forget.
And even if the coder reads and remembers, a code reader may not have.
Which is why I suggested multiple statements in explicit order when it
really matters.
tjr
More information about the Python-list
mailing list