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


Groups > comp.lang.python > #49105

Re: Is this PEP-able? fwhile

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python.list@tim.thechases.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; 'elif': 0.05; 'nicely': 0.07; 'subject:PEP': 0.07; 'appropriate.': 0.09; 'decorator': 0.09; 'toplevel': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; "(it's": 0.16; '-tkc': 0.16; 'dig': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'loop.': 0.16; 'loops': 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; 'java': 0.24; 'cc:no real name:2**0': 0.24; 'certain': 0.27; 'header:In-Reply-To:1': 0.27; 'specifically': 0.29; 'chris': 0.29; 'feature': 0.29; 'raise': 0.29; 'cc:2**2': 0.30; "i'm": 0.30; 'easier': 0.31; 'usually': 0.31; 'breaking': 0.31; 'return;': 0.31; "i'd": 0.34; 'could': 0.34; "can't": 0.35; 'something': 0.35; '(2)': 0.35; 'but': 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; 'to:addr:gmail.com': 0.65; 'subject:this': 0.83; 'arrive,': 0.84; 'popular;': 0.84; 'received:50.22': 0.84; '2013': 0.98
Date Mon, 24 Jun 2013 18:13:23 -0500
From Tim Chase <python.list@tim.thechases.com>
To Fábio Santos <fabiosantosart@gmail.com>
Subject Re: Is this PEP-able? fwhile
In-Reply-To <CAA=1kxRp6o4OX3ES70j+O0xrSPfyyoZsU5x-qvNegCaY3QBYaw@mail.gmail.com>
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>
X-Mailer Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu)
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - boston.accountservergroup.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - tim.thechases.com
Cc 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.3786.1372115499.3114.python-list@python.org> (permalink)
Lines 40
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1372115499 news.xs4all.nl 15901 [2001:888:2000:d::a6]:52011
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:49105

Show key headers only | View raw


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.

-tkc



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


Thread

Re: Is this PEP-able? fwhile Tim Chase <python.list@tim.thechases.com> - 2013-06-24 18:13 -0500

csiph-web