Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #8417

Re: Interpreting Left to right?

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder1.news.weretis.net!news.albasani.net!news2.arglkargh.de!news.wiretrip.org!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'python': 0.08; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'statement.': 0.09; 'target,': 0.09; 'wrote:': 0.15; '"="': 0.16; '(remember': 0.16; '*why*': 0.16; 'and)': 0.16; 'assigns': 0.16; 'evaluates': 0.16; 'expression.': 0.16; 'from:addr:acm.org': 0.16; 'received:198.144': 0.16; 'rhs': 0.16; 'tmp': 0.16; 'tuple)': 0.16; 'yet.': 0.19; "doesn't": 0.22; 'here?': 0.23; 'wrong?': 0.23; 'thus': 0.23; 'statement': 0.25; "i'm": 0.27; '(the': 0.28; 'raise': 0.28; 'fri,': 0.28; 'guess': 0.28; '24,': 0.29; 'object': 0.30; 'subject:?': 0.31; 'expression': 0.32; 'received:198': 0.32; 'list': 0.33; 'it.': 0.33; 'done': 0.33; 'header:User-Agent:1': 0.34; 'header:X-Complaints-To:1': 0.34; 'to:addr:python-list': 0.34; 'things': 0.35; 'that,': 0.35; 'assignment': 0.35; 'latter': 0.35; 'lists,': 0.35; 'charset:us-ascii': 0.36; 'url:python': 0.36; 'but': 0.37; 'received:org': 0.38; 'url:org': 0.38; 'subject:: ': 0.38; 'should': 0.39; 'perhaps': 0.39; 'header:Mime- Version:1': 0.39; 'url:docs': 0.39; 'list,': 0.39; 'to:addr:python.org': 0.39; 'case': 0.40; 'did': 0.40; 'where': 0.40; 'would': 0.40; 'target': 0.61; 'order': 0.62; 'here.': 0.66; 'jun': 0.67; 'article': 0.76; '"an': 0.84; 'sides.': 0.84; 'url:reference': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Ned Deily <nad@acm.org>
Subject Re: Interpreting Left to right?
Date Fri, 24 Jun 2011 15:10:18 -0700
References <BANLkTimcPAjQP4JJk=OAbrkLFfd2AtndwQ@mail.gmail.com> <iu1aaq$rni$1@dough.gmane.org> <4E043953.5080705@stoneleaf.us> <20110624195300.GJ6075@point.cs.wisc.edu> <4E04EFD4.6050309@stoneleaf.us> <20110624200618.GK6075@point.cs.wisc.edu> <nad-C01F34.13242424062011@news.gmane.org> <20110624210835.GL6075@point.cs.wisc.edu>
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host baybryj.net
User-Agent MT-NewsWatcher/3.5.3b3 (Intel Mac OS X)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.395.1308953433.1164.python-list@python.org> (permalink)
Lines 51
NNTP-Posting-Host 82.94.164.166
X-Trace 1308953433 news.xs4all.nl 512 [::ffff:82.94.164.166]:57928
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:8417

Show key headers only | View raw


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 comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Interpreting Left to right? Ned Deily <nad@acm.org> - 2011-06-24 15:10 -0700

csiph-web