Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #95912
| From | random832@fastmail.us |
|---|---|
| Subject | Re: packing unpacking depends on order. |
| Date | 2015-09-02 21:17 -0400 |
| References | <55E6C904.3020602@rece.vub.ac.be> <CAGuvt90dWASEjj=_GiZb4jqV4CDF+qqFLH4VS5m_qhUMx6jbJg@mail.gmail.com> <55E73159.4050508@mail.de> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.49.1441243048.8327.python-list@python.org> (permalink) |
On Wed, Sep 2, 2015, at 13:26, Sven R. Kunze wrote: > I agree as well. First evaluate the right side, then assign it to the > left side at once. The behavior, if it's *not* "first evaluating the right side", is indistinguishable from it by this test. Assigning the RHS of each case to a separate list yields the same result: >>> a, b = [1, 2, 3, 4, 5], 1 >>> abb = a[b], b >>> bab = b, a[b] >>> b, a[b] = abb >>> a [1, 2, 1, 4, 5] >>> a, b = [1, 2, 3, 4, 5], 1 >>> a[b], b = bab >>> a [1, 1, 3, 4, 5] What's happening is this: >>> abb = a[b], b # 2, 1 >>> bab = b, a[b] # 1, 2 then >>> b, a[b] = abb # b = 2; a[2] = 1 or >>> a[b], b = bab # a[1] = 1; b = 2 The question is what does "assign it to the left side at once" even *mean* in the presence of subscripts? Build up a list of object-subscript pairs (evaluating all the subscripts, including if any may have side effects) before executing any __setitem__? Why is the right side evaluated first? Why not build up this "assignment destination list" first, before evaluating the right side? They wouldn't be distinguished by this test, since the RHS has no side effects, but it'd be easy enough to devise such a test case.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: packing unpacking depends on order. random832@fastmail.us - 2015-09-02 21:17 -0400
csiph-web