Python 3000 idea: reversing the order of chained assignments
Steve Holden
steve at holdenweb.com
Thu Mar 22 04:54:02 EDT 2007
Terry Reedy wrote:
> "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.
Where? I'm looking at
http://docs.python.org/ref/assignment.html
right now.
> 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.
>
The current docs define
a, b = c, d
and
a = b, c, d
and
a, b, c = d
as valid assignments, but I can't find the part where
a = b = c
is defined. Help me out here. It looks as though the real syntax should
be something like
assignment_stmt ::= (target_list "=")+ expression_list |
(target_list "=")+ assignment_stmt
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com
More information about the Python-list
mailing list