Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.84.MISMATCH!newsfeed.xs4all.nl!newsfeed5.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.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'raised': 0.07; '(it': 0.09; 'raised,': 0.09; 'subject:error': 0.09; 'am,': 0.12; 'received:209.85.210.174': 0.13; 'received:mail- iy0-f174.google.com': 0.13; '(call': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'iterator': 0.16; 'iterator.': 0.16; 'swallow': 0.16; 'unpacking': 0.16; 'valueerror': 0.16; 'wrote:': 0.18; 'dec': 0.22; 'header:In-Reply- To:1': 0.22; 'values.': 0.23; 'times,': 0.24; 'all,': 0.28; 'raise': 0.28; "wasn't": 0.28; 'message-id:@mail.gmail.com': 0.28; 'temporary': 0.29; 'values': 0.32; 'list': 0.32; 'there': 0.33; 'fri,': 0.34; 'to:addr:python-list': 0.34; 'too': 0.34; 'but': 0.37; 'received:google.com': 0.37; 'received:209.85': 0.38; 'should': 0.39; 'received:209': 0.40; 'to:addr:python.org': 0.40; 'more': 0.61; '2011': 0.61; 'results': 0.63; 'roughly': 0.67; 'subject:day': 0.68; 'andrea': 0.84; 'yielded': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=dVZNmii+OLlo0/oebKWkCjWNbdsDXki/dZssXGFRY5Y=; b=KGnupyM6Ub77jjCcXRz1Ay5FWv7lxlNNKh1/Gq5TUN1q125Rb773XzX29CaHThyWuB 8oBtdEjg3LbFvo12p3gxrxZRpU2ftF95+gFQ3lfdA2+pCOQpf70zsWdjnt6dLzORymYa vGncNPRH/Jpwl+zW33zn+vhpQOQLm7lfdZxzY= MIME-Version: 1.0 In-Reply-To: <4EE0DDE4.4080802@gmail.com> References: <18647617.2258.1323358966076.JavaMail.geo-discussion-forums@yqf20> <4EE0DDE4.4080802@gmail.com> Date: Fri, 9 Dec 2011 03:21:31 +1100 Subject: Re: Misleading error message of the day From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 19 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1323361294 news.xs4all.nl 6863 [2001:888:2000:d::a6]:54214 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:16844 On Fri, Dec 9, 2011 at 2:55 AM, Andrea Crotti wrote: > Yes but how do you know how many values you generated when it quits? > I mean I don't know how it work internally, but it should keep a temporary > list of the yielded values to be able to find out how many values are > there.. Iterator unpacking works roughly thus: 1) Count up how many results you need (call that N) 2) N times, get a value from the iterator. If StopIteration is raised, swallow it and raise ValueError because there were too few values. 3) Attempt to get one more value from the iterator. If StopIteration is NOT raised, raise ValueError because there were too many values. At no point is the "total size" of the iterator counted (it could, after all, be infinite). When ValueError is raised, all that's known is that StopIteration wasn't raised at the end of the process. ChrisA