Python 3000 idea: reversing the order of chained assignments

Mark T nospam at nospam.com
Thu Mar 22 00:09:52 EDT 2007


"Marcin Ciura" <marcin.ciura at poczta.NOSPAMonet.pl> wrote in message 
news:ets9hc$74f$1 at news.onet.pl...
> Given
>   class Node(object):
>       pass
>
>   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.

-Mark T.

>
> as
>   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?
>   Marcin




More information about the Python-list mailing list