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


Groups > comp.lang.python > #53263

Re: semicolon at end of python's statements

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.012
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'python.': 0.02; 'syntax': 0.04; 'iterate': 0.09; 'shame': 0.09; 'assume': 0.14; '"new': 0.16; 'constructs': 0.16; 'expression,': 0.16; 'finney': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'loops': 0.16; 'sequence:': 0.16; 'suite.': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'seems': 0.21; 'example': 0.22; 'aug': 0.22; 'exists': 0.24; 'forming': 0.24; 'logical': 0.24; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'lot.': 0.31; 'subject:end': 0.31; 'writes:': 0.31; 'regular': 0.32; 'fri,': 0.33; "i'd": 0.34; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'version': 0.36; 'sequence': 0.36; 'possible': 0.36; 'similar': 0.36; 'two': 0.37; 'ben': 0.38; 'to:addr:python- list': 0.38; 'itself': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'full': 0.61; 'new': 0.61; 'simply': 0.61; 'times': 0.62; '30,': 0.65; 'line,': 0.68; 'skip:w 30': 0.69; 'repeat': 0.74; 'proves': 0.84; 'sometimes.': 0.84; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=dTLBNBxdCgsl3yg2iLqn/it35Z8W+BUGdJ1vZ3vRl6I=; b=DsGzVD9wqxmQXKBCxHoqnfCSutlSjqCR6NxXWmYyCULn5ou2VXfzyKnl9xK3E0PGHw DGgtC5xVztRzj5gNp48sXsXgt//kxSSKJbOBXB2KdjS2X0Z30d+ptTSkCnAv8SA+LcPL aCeJPZKIg38Mmg2a0MrZG9hoKVQQTAi1/H5sO4J7aGf5xiNmDERZuvOWAsr9LZ1MNFmn JptC83dG27McK+pn9nt5JXebfKTCMMPSzUz6oHB06kibLDUhbvS8YW+6W6Yxj049gnOq 8V6iCfu6a2BxjY3Vheex2PhC1KwuzjNM49Hwp18RgmZEU7fmH2NJ4/6rv54SPKwUcy7T eWHQ==
MIME-Version 1.0
X-Received by 10.58.100.234 with SMTP id fb10mr5179162veb.5.1377816612860; Thu, 29 Aug 2013 15:50:12 -0700 (PDT)
In-Reply-To <7wob8gywds.fsf@benfinney.id.au>
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>
Date Fri, 30 Aug 2013 08:50:12 +1000
Subject Re: semicolon at end of python's statements
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
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.375.1377816621.19984.python-list@python.org> (permalink)
Lines 34
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1377816621 news.xs4all.nl 15905 [2001:888:2000:d::a6]:56971
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:53263

Show key headers only | View raw


On Fri, Aug 30, 2013 at 8:17 AM, Ben Finney <ben+python@benfinney.id.au> wrote:
> Fábio Santos <fabiosantosart@gmail.com> writes:
>
>> It is a shame that this is not possible in python. for..if exists in
>> comprehensions and not in regular loops but that would be nice
>> sometimes.
>
> So you use it in a generator expression, and iterate over the generator:
>
>     for foo in (spam for spam in sequence if predicate(spam)):
>         process(spam)
>
> That way, there's no need for new syntax.

That works for the specific example of a for loop (and proves that
it's logical and sensible to iterate over part of a loop). But how
many times has something similar come up - like the
while-loop-that-retains-its-value suggestion a while ago? Sometimes,
the only "new syntax" required is a weakening of the rule that one
thing goes on one line, and then the syntax is simply two block
constructs forming a single loop header.

Also, the genexp version you have above seems to repeat itself a lot.
I'd write that as simply:

for spam in sequence: if predicate(spam):
    process(spam)

though of course, if the processing is a single function call, there
are other ways to lay it out. But assume that the processing is a full
suite.

ChrisA

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