A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2012-November/122553.html below:

[Python-Dev] chained assignment weirdity

[Python-Dev] chained assignment weirdityDevin Jeanpierre jeanpierreda at gmail.com
Tue Nov 6 09:54:08 CET 2012
On Tue, Nov 6, 2012 at 1:18 AM, Chris Withers <chris at simplistix.co.uk> wrote:
> Hi All,
>
> I bumped into this using Michael Foord's Mock library.
> It feels like a bug to me, but thought I'd ask here before logging one in
> the tracker in case people know that we won't be able to fix it:
>
> On 05/11/2012 13:43, Michael Foord wrote:
>>
>>
>>>>>>> class Foo(object):
>>>>
>>>> ...  def __setattr__(s, k, v):
>>>> ...   print k
>>>> ...
>>>>>>>
>>>>>>> f = Foo()
>>>>>>>
>>>>>>> f.g = f.x = 3
>>>>
>>>> g
>>>> x
>>>

It's terrible and counter-intuitive, but it is documented. See:
http://docs.python.org/2/reference/simple_stmts.html#assignment-statements

Notice that it proclaims that target lists are assigned to from left
to right. That's the behavior you've noticed.

On the other hand, one might easily misread this piece of
documentation, which implies right to left assignment:
http://docs.python.org/2/reference/expressions.html#evaluation-order

But the last note doesn't look normative to me.

(I'm not a dev, just trying to be helpful.)

-- Devin
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4