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


Groups > comp.lang.python > #53515

Re: semicolon at end of python's statements

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <albert.visser@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'syntax': 0.04; 'value,': 0.04; 'context': 0.07; 'nested': 0.07; 'referring': 0.07; 'ambiguity': 0.09; 'clause': 0.09; 'moreover,': 0.09; 'parsed': 0.09; "wouldn't": 0.14; "'w')": 0.16; '(besides': 0.16; '10:45': 0.16; 'clause.': 0.16; 'client:': 0.16; 'colons': 0.16; 'construct.': 0.16; 'for"': 0.16; 'for,': 0.16; 'nesting': 0.16; 'programmer,': 0.16; 'slicing,': 0.16; 'subject:python': 0.16; 'all.': 0.16; 'wrote:': 0.18; 'seems': 0.21; '>>>': 0.22; 'bonus': 0.22; 'header:User-Agent:1': 0.23; 'filtering': 0.24; "shouldn't": 0.24; 'specify': 0.24; 'mon,': 0.24; 'header:In- Reply-To:1': 0.27; 'idea': 0.28; 'am,': 0.29; 'raise': 0.29; 'related': 0.29; "i'm": 0.30; '(which': 0.31; 'lines': 0.31; '>>>>': 0.31; "d'aprano": 0.31; 'sep': 0.31; 'steven': 0.31; 'subject:end': 0.31; 'another': 0.32; 'sense': 0.34; 'could': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; '+0200,': 0.36; 'should': 0.36; 'two': 0.37; 'being': 0.38; 'skip:o 20': 0.38; 'e.g.': 0.38; 'to:addr:python- list': 0.38; 'rather': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'url:mail': 0.40; 'how': 0.40; 'above,': 0.60; 'then,': 0.60; 'managers': 0.61; 'mentioned': 0.61; 'first': 0.61; 'back': 0.62; 'show': 0.63; 'kind': 0.63; 'become': 0.64; 'different': 0.65; 'line,': 0.68; 'obvious': 0.74; 'saw': 0.77; 'ambiguous': 0.84; 'pardon': 0.84; 'albert': 0.91; 'dutch': 0.91; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:to:subject:references:date:mime-version :content-transfer-encoding:from:message-id:in-reply-to:user-agent; bh=ME/koqeDJOSpfhd2GxlcGzxBwvCRt4ySM+fkaIKm29s=; b=gPHtfPVpFMenVeHrRthFJOH+kDeBkqO4+F+XGdEM3j8dlB07+zC047KPJko0OMjARf vVIPvMQeZGKv5+HYqUh6mAp0yCcjIK3ZdHRpMN4df1nbY61aARR2XOMVv+fiO7He/7Uw Zqk2bCEq6HmZ9j7l/7WNwBq7kA1ru3TqbpIk+i3XU2BgTemXfdMRMHHRkaxOiMSLpnKA xV3vo8rKYmAkw9LHtaNTJpsFbJeHqhjeJxPBIpL55D/IGwyD8rfQPt+YO8fNKq82x76M F0A7dTVGzZuYj515RDdGBbrW8ezVwDMHplGLBiTNVQ9ai03ZtU/e4dAIUpbzNWoPgMpc yAwQ==
X-Received by 10.180.182.228 with SMTP id eh4mr14546828wic.45.1378143875981; Mon, 02 Sep 2013 10:44:35 -0700 (PDT)
Content-Type text/plain; charset=utf-8; format=flowed; delsp=yes
To python-list@python.org
Subject Re: semicolon at end of python's statements
References <1377735506.18906.15.camel@debian> <mailman.347.1377760274.19984.python-list@python.org> <1FETt.52607$Mw4.14965@fx15.am4> <CAPTjJmpBbf=BkZdeg3VdBYFvB0ADtyseGAMB214jJDyqZa=pmQ@mail.gmail.com> <CAA=1kxR_pT=MsUSSk0v-oij-0hSh0LEYrrP5i+5MukmcYfOGWA@mail.gmail.com> <7wob8gywds.fsf@benfinney.id.au> <mailman.385.1377858745.19984.python-list@python.org> <52213435$0$6599$c3e8da3$5496439d@news.astraweb.com> <mailman.458.1378068912.19984.python-list@python.org> <522446ae$0$2743$c3e8da3$76491128@news.astraweb.com> <52245E2F.4020909@rece.vub.ac.be> <52246BAD.9050403@gmail.com> <52246F4F.7080108@rece.vub.ac.be>
Date Mon, 02 Sep 2013 19:44:33 +0200
MIME-Version 1.0
Content-Transfer-Encoding Quoted-Printable
From "albert visser" <albert.visser@gmail.com>
In-Reply-To <52246F4F.7080108@rece.vub.ac.be>
User-Agent Opera Mail/12.16 (Linux)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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.508.1378143885.19984.python-list@python.org> (permalink)
Lines 97
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1378143885 news.xs4all.nl 15879 [2001:888:2000:d::a6]:55774
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:53515

Show key headers only | View raw


On Mon, 02 Sep 2013 12:58:23 +0200, Antoon Pardon  
<antoon.pardon@rece.vub.ac.be> wrote:

> Op 02-09-13 12:42, Fábio Santos schreef:
>> On 09/02/2013 10:45 AM, Antoon Pardon wrote:
>>> Op 02-09-13 10:05, Steven D'Aprano schreef:

[...]

>>>>
>>>> for item in seq: if cond:
>>>>      do_this()
>>>>      do_that()
>>>> else:
>>>>      do_something else()
>>>>
>>>> which is still nonsense but won't raise SyntaxError.
>>> Why shouldn't this raise a SyntaxError?
>>>
>> Because it would be parsed as a valid for .. else construct. Either that
>> or become ambiguous to the programmer, who would not be sure whether he
>> was writing an else clause for the `if`, or for the `for`.
>

[...]
>
> I also don't see how this would be that ambigous. The else
> lines up with the for, so it seems rather obvious for which
> he was writing an else clause.
>

My first association would be with the for, but someone could also be  
thinking it's referring to the if on the same line, because there wouldn't  
be any other way to write it (besides nesting the if).

I wouldn't like this syntax anyway, two colons and all.

When I first saw the idea of a nested for .. if construct the thing that  
came to mind was another nesting, namely that of context managers. While I  
don't mind using

     with <context-1>:
         with <context-2>:
             do_stuff

I like being able to do e.g.

     with open('some_file') as _in, open('another_file', 'w') as _out:

because it makes it obvious that the context managers are related.
Expressing that the for and the if are related also appeals to me.
Another parallel might be slicing, where you can specify not only a start  
and an end value, but also an interval (which could be seen as a kind of  
filtering condition).

I think that if you really want to show the "filtered for" as a somewhat  
different concept than a for that just happens to have an if in its suite,  
that should be made visible.
Coming back to my first association mentioned above, why not use a comma?

for <identifier> in <iterable>, <condition>:
     <stuff>

(come to think of it, it has the added bonus that you won't get ambiguity  
what an else might be about).


Somehow this makes sense to me. But then, I also like 'x = y if  
<condition> else z'.
Moreover, I'm Dutch (...)

Albert Visser
-- 
Using Opera's mail client: http://www.opera.com/mail/

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


Thread

Re: semicolon at end of python's statements "Sam Fourman Jr." <sfourman@gmail.com> - 2013-08-28 22:10 -0400
  Re: semicolon at end of python's statements Alister <alister.ware@ntlworld.com> - 2013-08-29 09:39 +0000
    Re: semicolon at end of python's statements Chris Angelico <rosuav@gmail.com> - 2013-08-29 19:52 +1000
    Re: semicolon at end of python's statements Fábio Santos <fabiosantosart@gmail.com> - 2013-08-29 11:02 +0100
    Re: semicolon at end of python's statements Ben Finney <ben+python@benfinney.id.au> - 2013-08-30 08:17 +1000
    Re: semicolon at end of python's statements Chris Angelico <rosuav@gmail.com> - 2013-08-30 08:50 +1000
    Re: semicolon at end of python's statements Ben Finney <ben+python@benfinney.id.au> - 2013-08-30 14:55 +1000
    Re: semicolon at end of python's statements Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-08-30 09:15 +0200
    Re: semicolon at end of python's statements Chris Angelico <rosuav@gmail.com> - 2013-08-30 17:25 +1000
    Re: semicolon at end of python's statements Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-08-30 09:48 +0200
    Re: semicolon at end of python's statements Fábio Santos <fabiosantosart@gmail.com> - 2013-08-30 11:32 +0100
      Re: semicolon at end of python's statements Roy Smith <roy@panix.com> - 2013-08-30 06:53 -0400
        Re: semicolon at end of python's statements Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-08-30 16:14 +0200
        Re: semicolon at end of python's statements Chris Angelico <rosuav@gmail.com> - 2013-08-31 08:18 +1000
      Re: semicolon at end of python's statements Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-31 00:09 +0000
        Re: semicolon at end of python's statements Terry Reedy <tjreedy@udel.edu> - 2013-08-31 01:03 -0400
        Re: semicolon at end of python's statements Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-08-31 10:47 +0300
          Re: semicolon at end of python's statements Paul Rudin <paul.nospam@rudin.co.uk> - 2013-08-31 09:00 +0100
            Re: semicolon at end of python's statements Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-08-31 13:28 +0300
            Re: semicolon at end of python's statements Grant Edwards <invalid@invalid.invalid> - 2013-09-02 14:20 +0000
              Re: semicolon at end of python's statements Tim Chase <python.list@tim.thechases.com> - 2013-09-02 09:45 -0500
                Re: semicolon at end of python's statements Roy Smith <roy@panix.com> - 2013-09-02 10:47 -0400
                Re: semicolon at end of python's statements Tim Chase <python.list@tim.thechases.com> - 2013-09-02 12:58 -0500
                Re: semicolon at end of python's statements Chris Angelico <rosuav@gmail.com> - 2013-09-03 07:07 +1000
        Re: semicolon at end of python's statements Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-09-01 19:58 +0200
        Re: semicolon at end of python's statements Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-09-01 21:58 +0200
          Re: semicolon at end of python's statements Steven D'Aprano <steve@pearwood.info> - 2013-09-02 08:05 +0000
            Re: semicolon at end of python's statements Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-09-02 11:45 +0200
            Re: semicolon at end of python's statements Fábio Santos <fabiosantosart@gmail.com> - 2013-09-02 11:42 +0100
            Re: semicolon at end of python's statements Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-09-02 12:58 +0200
            Re: semicolon at end of python's statements "albert visser" <albert.visser@gmail.com> - 2013-09-02 19:44 +0200
              Re: semicolon at end of python's statements Roy Smith <roy@panix.com> - 2013-09-02 13:53 -0400
                Re: semicolon at end of python's statements Neil Cerutti <neilc@norwich.edu> - 2013-09-03 17:15 +0000
                Re: semicolon at end of python's statements Neil Cerutti <neilc@norwich.edu> - 2013-09-03 20:00 +0000
            Re: semicolon at end of python's statements Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-09-02 17:24 -0400
        Re: semicolon at end of python's statements MRAB <python@mrabarnett.plus.com> - 2013-09-02 00:30 +0100
        Re: semicolon at end of python's statements Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-09-02 10:29 +0200
          Re: semicolon at end of python's statements Steven D'Aprano <steve@pearwood.info> - 2013-09-02 09:52 +0000
            Re: semicolon at end of python's statements Chris Angelico <rosuav@gmail.com> - 2013-09-02 20:14 +1000
              Re: semicolon at end of python's statements Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-02 14:57 +0000
            Re: semicolon at end of python's statements Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-09-02 12:52 +0200
            Re: semicolon at end of python's statements Modulok <modulok@gmail.com> - 2013-09-02 17:17 -0600
              Re: semicolon at end of python's statements Roy Smith <roy@panix.com> - 2013-09-02 19:54 -0400
                Re: semicolon at end of python's statements Modulok <modulok@gmail.com> - 2013-09-02 18:56 -0600

csiph-web