Suggestions for 2002
Mark McEahern
marklists at mceahern.com
Sat Jan 12 22:50:48 EST 2002
> "Raymond Hettinger" <othello at javanet.com> writes:
> Suggestion #1: Issue a dubious syntax warning for multiple
> assignments where there are overlaps between the assigned-to
> variables:
>
> >>> a = ['cat','dog']
> >>> i = 1
> >>> i, a[i] = 0, 'boo'
> >>> a
> ['boo', 'dog'] # not ['cat','boo'] which was expected
>
> I'd call this an outright Python bug even if it's documented in the
> reference manual. What's the justification? From the doc, it appears
> that even x,y=y,x only works for fairly subtle reasons. This seems
> bogus. It would be better if assigning a sequence made a temporary
> sequence of the target values before assigning.
What would you expect here (breaking the multiple assignment up into
separate assignment)?
>>> a = ['cat','dog']
>>> i = 1
>>> i = 0
>>> a[i] = 'boo'
>>> a
Clearly, you'd expect ['boo', 'dog'].
So where's the problem?
// mark
More information about the Python-list
mailing list