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


Groups > comp.lang.python > #8413

Re: Interpreting Left to right?

Date 2011-06-24 16:21 -0500
From Tycho Andersen <tycho@tycho.ws>
Subject Re: Interpreting Left to right?
References (2 earlier) <4E043953.5080705@stoneleaf.us> <20110624195300.GJ6075@point.cs.wisc.edu> <4E04EFD4.6050309@stoneleaf.us> <20110624200618.GK6075@point.cs.wisc.edu> <iu2u0a$hre$1@dough.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.392.1308951083.1164.python-list@python.org> (permalink)

Show all headers | View raw


On Fri, Jun 24, 2011 at 05:02:00PM -0400, Terry Reedy wrote:
> On 6/24/2011 4:06 PM, Tycho Andersen wrote:
> 
> >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.
> 
> You are parsing "a = b = c" as "a = (b = c)" which works in a
> language in which assignment is an expression, but does not work in
> Python where assignment is a statement. You have to parse it more as
> "(a = b) = c" but that does not work since then the first '=' is not
> what it seems. It is more like "(both a and b) = c". Perhaps best to
> expand "a = b = c" to "a = c; b = c" and see the first as an
> abbreviation thereof -- just delete the 'c;'.
> 
> If I have ever used this sort of multiple assignment, it has been
> for simple unambiguous things like "a = b = 0".

Ah, the point about the grammar is what I was missing. Thanks a bunch!

\t

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Interpreting Left to right? Tycho Andersen <tycho@tycho.ws> - 2011-06-24 16:21 -0500

csiph-web