Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #8417 > unrolled thread
| Started by | Ned Deily <nad@acm.org> |
|---|---|
| First post | 2011-06-24 15:10 -0700 |
| Last post | 2011-06-24 15:10 -0700 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Interpreting Left to right? Ned Deily <nad@acm.org> - 2011-06-24 15:10 -0700
| From | Ned Deily <nad@acm.org> |
|---|---|
| Date | 2011-06-24 15:10 -0700 |
| Subject | Re: Interpreting Left to right? |
| Message-ID | <mailman.395.1308953433.1164.python-list@python.org> |
In article <20110624210835.GL6075@point.cs.wisc.edu>,
Tycho Andersen <tycho@tycho.ws> wrote:
> On Fri, Jun 24, 2011 at 01:24:24PM -0700, Ned Deily wrote:
> > In article <20110624200618.GK6075@point.cs.wisc.edu>,
> > Tycho Andersen <tycho@tycho.ws> wrote:
> > > Yes, I understand that, but I guess I don't understand *why* things
> > > are done that way. What is the evaluation order principle at work
> > > here? I would have expected:
> > >
> > > tmp = {}
> > > x['huh'] = tmp # NameEror!
> > >
> > > That is, the right hand sides of assignments are evaluated before the
> > > left hand sides. That is (somehow?) not the case here.
> >
> > http://docs.python.org/py3k/reference/simple_stmts.html#assignment-statement
> > s
>
> Perhaps I'm thick, but (the first thing I did was read the docs and) I
> still don't get it. From the docs:
>
> "An assignment statement evaluates the expression list (remember that
> this can be a single expression or a comma-separated list, the latter
> yielding a tuple) and assigns the single resulting object to each of
> the target lists, from left to right."
>
> For a single target, it evaluates the RHS and assigns the result to
> the LHS. Thus
>
> x = x['foo'] = {}
>
> first evaluates
>
> x['foo'] = {}
>
> which should raise a NameError, since x doesn't exist yet. Where am I
> going wrong?
"An assignment statement evaluates the expression list (remember that
this can be a single expression or a comma-separated list, the latter
yielding a tuple) and assigns the single resulting object to each of the
target lists, from left to right."
Also, remember that in Python the "=" is not part of an expression.
It's a token in the assignment statement.
--
Ned Deily,
nad@acm.org
Back to top | Article view | comp.lang.python
csiph-web