Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.029 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'terry': 0.07; 'problem:': 0.09; 'exception': 0.12; "'',": 0.16; 'iterator.': 0.16; 'pulled': 0.16; 'reedy': 0.16; 'termination': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.16; 'cheers,': 0.18; 'cc:no real name:2**0': 0.20; 'cc:2**0': 0.22; 'header:In-Reply-To:1': 0.22; 'appear': 0.23; 'body.': 0.23; 'breaks': 0.23; 'exhibit': 0.23; 'sep': 0.23; 'though.': 0.23; 'pm,': 0.24; 'function': 0.27; 'loop': 0.28; 'message-id:@mail.gmail.com': 0.29; 'cc:addr:python.org': 0.30; 'example': 0.30; 'sun,': 0.30; 'thanks': 0.30; "skip:' 10": 0.30; 'equivalent': 0.31; 'received:209.85.161.46': 0.31; 'received :mail-fx0-f46.google.com': 0.31; 'error': 0.32; 'pointing': 0.32; 'does': 0.32; 'actually': 0.33; "can't": 0.33; "i've": 0.34; 'right,': 0.34; 'subject:next': 0.34; 'received:209.85.161': 0.35; 'before.': 0.37; 'but': 0.37; 'received:google.com': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.39; 'under': 0.39; 'called': 0.40; 'might': 0.40; 'your': 0.61; 'body': 0.61; 'results': 0.61; 'full': 0.63; '11,': 0.68; 'amazing': 0.68; 'saw': 0.69; 'claim': 0.76; 'fight': 0.80; 'yours': 0.85 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=5Fk3ewozsSaj4ZI9SVR2BT6JuLPSEokHZtjsPUPr8A4=; b=V4tWuGYEaoYJzn8RAPN/x1yc7pwvm0SbUppoyWUNnyN2At/nZhaTcXQ8goMzydnHo+ AOprbqlM2hOHA6SD9SikhtJcLN2p0tg5J7co43MgsYaKjc1bTDMiQdnVFY13gs+C06K0 T9ow6ktlRUGUDbo1nFS7pJdZJPTNWgbRCKH1s= MIME-Version: 1.0 In-Reply-To: References: From: Ian Kelly Date: Mon, 12 Sep 2011 10:55:14 -0600 Subject: Re: Idioms combining 'next(items)' and 'for item in items:' To: Terry Reedy Content-Type: text/plain; charset=ISO-8859-1 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1315846863 news.xs4all.nl 2532 [2001:888:2000:d::a6]:52082 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:13189 On Sun, Sep 11, 2011 at 6:45 PM, Terry Reedy wrote: > whereas, you are right, it breaks it noisily in the body. So Ian's claim > that StopIteration must be caught to avoid silent termination is not true. > Thanks for pointing out what I saw but did not cognize the full implication > of before. A better exception and an error message with an explaination > might still be a good idea, though. But you can't write the function under the assumption that it will only be called from the function body. The following is a slight reorganization of your example that does exhibit the problem: for title in map(fix_title, ['amazinG', 'a helL of a fiGHT', '', 'igNordEd']): print(title) Output: amazing a Hell of a Fight Note that at first glance, my example would appear to be functionally equivalent to yours -- I've merely pulled the fix_title call out of the loop body and into the iterator. But actually they produce different results because fix_title misbehaves by not catching the StopIteration. Cheers, Ian