Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!nx01.iad01.newshosting.com!newshosting.com!news2.euro.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'raised': 0.07; 'received:verizon.net': 0.07; 'terry': 0.07; 'python': 0.08; '>>>>': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'am,': 0.12; 'exception': 0.12; 'case.': 0.15; "'',": 0.16; '3.2,': 0.16; 'reedy': 0.16; 'termination': 0.16; 'mon,': 0.16; 'wrote:': 0.16; 'jan': 0.19; '(most': 0.21; 'header:In-Reply-To:1': 0.22; 'body.': 0.23; 'breaks': 0.23; 'sep': 0.23; 'though.': 0.23; 'pm,': 0.24; 'traceback': 0.24; 'code': 0.25; 'saying': 0.26; 'loop': 0.28; 'skip:% 10': 0.30; 'thanks': 0.30; 'least': 0.31; 'error': 0.32; 'chris': 0.32; 'pointing': 0.32; "isn't": 0.33; 'to:addr:python- list': 0.33; '...': 0.34; 'header:User-Agent:1': 0.34; 'right,': 0.34; 'last):': 0.34; 'subject:next': 0.34; 'header:X-Complaints- To:1': 0.35; 'file': 0.36; 'before.': 0.37; 'but': 0.37; 'received:org': 0.38; 'subject:: ': 0.39; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'might': 0.40; "it's": 0.40; 'full': 0.63; 'saw': 0.69; 'claim': 0.76 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Idioms combining 'next(items)' and 'for item in items:' Date: Sun, 11 Sep 2011 20:45:41 -0400 References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-74-109-121-73.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20110812 Thunderbird/6.0 In-Reply-To: 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: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1315788359 news.xs4all.nl 2526 [2001:888:2000:d::a6]:60605 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:13152 On 9/11/2011 6:41 PM, Chris Angelico wrote: > On Mon, Sep 12, 2011 at 2:47 AM, Terry Reedy wrote: >> What you are saying is a) that the following code >> >> for title in ['amazinG', 'a helL of a fiGHT', '', 'igNordEd']: >> print(fix_title(title)) > At least in Python 3.2, this isn't the case. StopIteration breaks the > loop only if it's raised during the assignment, not during the body. It breaks the loop *silently* only if ... >>>> x=iter([1,2,3,4,5]) >>>> for i in x: > print("%d - %d"%(i,next(x))) > > 1 - 2 > 3 - 4 > Traceback (most recent call last): > File "", line 2, in > print("%d - %d"%(i,next(x))) > StopIteration 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. -- Terry Jan Reedy