Python 3000 idea: reversing the order of chained assignments

Virgil Dupras hardcoded.software at gmail.com
Thu Mar 22 02:56:02 CET 2007


On Mar 21, 9:24 pm, Steve Holden <s... at holdenweb.com> wrote:
> Marcin Ciura wrote:
> > Steven D'Aprano wrote:
> >>>>> x, y, z = 1, 2, 3
> >>>>> x = y = z
> >>>>> x, y, z
> >> (3, 3, 3)
>
> >> I certainly wouldn't expect to get (2, 3, 3).
>
> > Neither would I. I must have expressed myself not clearly enough.
> > Currently
> > x = y = z
> > is roughly equivalent to
> > x = z
> > y = z
> > I propose to change it to
> > y = z
> > x = z
> > Cheers,
> >    Marcin
>
> The difference being ... ?
> --
> 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

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.

>>> class Node:
...     pass
...
>>> node = Node()
>>> nextnode = Node()
>>> backup_node = node
>>> node = node.next = nextnode
>>> node.next is node
True
>>> hasattr(backup_node,'next')
False




More information about the Python-list mailing list