Python 3000 idea: reversing the order of chained assignments
nospam at nospam.com
Thu Mar 22 05:09:52 CET 2007
"Marcin Ciura" <marcin.ciura at poczta.NOSPAMonet.pl> wrote in message
news:ets9hc$74f$1 at news.onet.pl...
> class Node(object):
> node = Node()
> nextnode = Node()
> I tried to refactor the following piece of code
> node.next = nextnode
> node = nextnode
You have an error above. The first node's "next" points to nextnode, then
node is reassigned to point to nextnode, losing the original node!
The refactoring below is doing the same thing. It is, however, evaluating
right-to-left as you want. nextnode is place in node.next and placed in
node, also losing the original value of node.
> node = node.next = nextnode
> only to discover that Python performs chained assignments
> backwards compared to other languages, i.e. left-to-right
> instead of right-to-left. From the user's perspective,
> I can't think of any reasonable argument for keeping it
> this way in Python 3000. What is your opinion?
More information about the Python-list