"Virgil Dupras" <[EMAIL PROTECTED]> wrote:

> I think I see what Marcin means. The 'node' is changed too fast in the
> chain, and next is assigned to 'nextnode' instead of being assigned to
> node.

I can see why Marcin was confused. Many other languages assignment is an 
expression, so a=b=c is simply a=(b=c). In Python it isn't an expression, 
the chained assignment is a specific part of the syntax, so (as with 
chained comparisons) the semantics may be surprising to the uninitiated.

As a matter of interest do PyLint or PyChecker check for this situation 
(chained assignment where the target of an assignment is also a 
subexpression of a later assignment)?

Also it may be worth noting that unpacking has a similar behaviour:

   node, node.next = nextnode, nextnode

has the same result as the chained assignment: the RHS is a tuple and is 
fully evaluated before the assignment, but the LHS is not a tuple and the 
assignment happens strictly left to right with each assignment fully 
completed before proceeding to the next one.

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to