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


Groups > comp.lang.python > #49140

Re: Is this PEP-able? fwhile

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <joshua.landau.ws@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'syntax': 0.04; 'elif': 0.05; 'guido': 0.05; 'nicely': 0.07; 'subject:PEP': 0.07; 'agree,': 0.09; 'appropriate.': 0.09; 'decorator': 0.09; 'toplevel': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; "(it's": 0.16; 'dig': 0.16; 'loop.': 0.16; 'loops': 0.16; 'to:addr:python.list': 0.16; 'to:addr:tim.thechases.com': 0.16; 'to:name:tim chase': 0.16; 'component': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'starts': 0.20; '(the': 0.22; 'import': 0.22; 'cc:addr:gmail.com': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**1': 0.23; 'java': 0.24; 'certain': 0.27; 'header:In-Reply-To:1': 0.27; 'specifically': 0.29; 'chris': 0.29; 'feature': 0.29; 'raise': 0.29; 'tim': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'easier': 0.31; 'usually': 0.31; 'breaking': 0.31; 'chase': 0.31; 'return;': 0.31; 'says': 0.33; "i'd": 0.34; 'could': 0.34; "can't": 0.35; 'something': 0.35; '(2)': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'done': 0.36; 'skip:b 40': 0.39; 'sure': 0.39; 'either': 0.39; 'even': 0.60; 'catch': 0.60; 'ian': 0.60; 'subject:? ': 0.60; 'break': 0.61; 'such': 0.63; 'love': 0.65; 'reads': 0.68; 'subject:this': 0.83; 'arrive,': 0.84; 'gold.': 0.84; 'guido.': 0.84; 'popular;': 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:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=/udC5Gwd4e6JI0Qn760nrt7uIv34VMUgte8TYv5/TWg=; b=OzsYM8Vbai9yDMZOFZMNV3wFFSR4YqlzAQ5NXgDgnv1GyNwaCVdKxoZM5Ksi+nTxZF lMUFuZAxvttnkJqGRptxCPjTub0cPjYVhptfYamliSNNA1TE6mE6eFSxxk33Y6hkMrWA 0QZPL12vdLWbnJUduPVNhHY8P75/c6IjNi/4KSIo9TjOLfOw4KDOPrM6Yg+RcMJRWpIl JGTuA6ZlXixaRPqiOYZ8JR//Sll5+7jJ/SJuFqNa/sTWsoiZq8tjVcUJt6UuBAhFJuX9 NsffWUDugVfqioCQRMdbeo5Phky0/hK8qQSrAqCMAaBO/YVCLF0s+w+eqjnh5ggpy5/t 2REw==
X-Received by 10.112.42.44 with SMTP id k12mr10606661lbl.63.1372147523196; Tue, 25 Jun 2013 01:05:23 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <20130624181323.642ee428@bigbox.christie.dr>
References <8D03F2B8CF0E7BE-1864-1796B@webmail-m103.sysops.aol.com> <CAPTjJmrwNyF2-J8F3ii8W4WpkrNC67+i88ODLyiqHGa_7bz0Xg@mail.gmail.com> <20130624173050.5e16debf@bigbox.christie.dr> <CAA=1kxRp6o4OX3ES70j+O0xrSPfyyoZsU5x-qvNegCaY3QBYaw@mail.gmail.com> <20130624181323.642ee428@bigbox.christie.dr>
From Joshua Landau <joshua.landau.ws@gmail.com>
Date Tue, 25 Jun 2013 09:04:43 +0100
Subject Re: Is this PEP-able? fwhile
To Tim Chase <python.list@tim.thechases.com>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
Cc python-list <python-list@python.org>
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.3803.1372147834.3114.python-list@python.org> (permalink)
Lines 46
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1372147834 news.xs4all.nl 15928 [2001:888:2000:d::a6]:51178
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:49140

Show key headers only | View raw


On 25 June 2013 00:13, Tim Chase <python.list@tim.thechases.com> wrote:
> On 2013-06-24 23:39, Fábio Santos wrote:
>> On 24 Jun 2013 23:35, "Tim Chase" wrote:
>> > On 2013-06-25 07:38, Chris Angelico wrote:
>> > > Python has no issues with breaking out of loops, and even has
>> > > syntax specifically to complement it (the 'else:' clause). Use
>> > > break/continue when appropriate.
>> >
>> > from minor_gripes import breaking_out_of_nested_loops_to_top_level
>>
>> for x, y in itertools.product(range(width), range(height)):
>
> This works nicely for certain use cases, but if there's additional
> processing that needs to be done in the outer loops, it starts to get
> hairy.  As Ian Kelly mentions, I could really dig a labeled
> break/continue in Python (it's one of the few ideas I like that Java
> made pretty popular; though I can't say I particularly care for
> Java's implementation).  I'd love to see something like a decorator
> where you could do things like the following pseudocode:
>
>   @toplevel
>   for i in range(height):
>     for j in range(width):
>       for component in data[i,j]:
>         if condition:
>           continue toplevel
>         elif other_condition:
>           break toplevel
>         else:
>           other processing
>
> I'm not sure such a feature would ever arrive, but it would make it
> easier than the current recommendation which is usually to either (1)
> make inner loops into functions from which you can return; or (2)
> raise a custom exception and then catch it in the outer loop.

Guido says no; supposedly you can always just use a function. I don't
agree, but I'm not Guido.

Anyhoo, I prefer:

for i in range(height) as toplevel:
    for j in range(width):
        break from toplevel

Which reads like pure Python gold.

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


Thread

Re: Is this PEP-able? fwhile Joshua Landau <joshua.landau.ws@gmail.com> - 2013-06-25 09:04 +0100

csiph-web