Python 3000 idea: reversing the order of chained assignments
Terry Reedy
tjreedy at udel.edu
Thu Mar 22 14:42:48 EDT 2007
"Steve Holden" <steve at holdenweb.com> wrote in message
news:ettg9s$t94$1 at sea.gmane.org...
| Terry Reedy wrote:
| > The assignment order is specified in the language reference.
|
| Where? I'm looking at
|
| http://docs.python.org/ref/assignment.html
|
| right now.
The first line of the syntax grammar is:
assignment_stmt ::= (target_list "=")+ expression_list
The '+' means 1 or more 'target_list =' occurances.
The first line of the semantic explanation is:
" An assignment statement evaluates the expression list (...) and assigns
the single resulting object to each of the target lists, from left to
right."
Left to right.
And one can also check the byte code:
>>> dis.dis(compile('a=b=c', '', 'single'))
1 0 LOAD_NAME 0 (c)
3 DUP_TOP
4 STORE_NAME 1 (a)
7 STORE_NAME 2 (b)
10 LOAD_CONST 0 (None)
13 RETURN_VALUE
| 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
You only need the first line (see above).
Terry Jan Reedy
More information about the Python-list
mailing list