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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '3.2': 0.05; 'received:verizon.net': 0.07; 'terry': 0.07; 'python': 0.08; '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; 'iterator.': 0.16; 'reedy': 0.16; 'this:': 0.16; 'wrote:': 0.16; 'subject:question': 0.18; '2.x': 0.18; 'jan': 0.19; 'header:In- Reply-To:1': 0.22; 'pm,': 0.24; 'code.': 0.26; 'classes': 0.28; 'depends': 0.28; 'version.': 0.29; '3.x': 0.30; 'confused': 0.30; 'use?': 0.30; 'class': 0.30; 'change.': 0.32; 'to:addr:python- list': 0.33; 'header:User-Agent:1': 0.34; '2.6': 0.34; 'header:X -Complaints-To:1': 0.35; 'unless': 0.36; 'but': 0.37; 'something': 0.37; 'could': 0.38; 'received:org': 0.38; 'some': 0.38; 'should': 0.38; 'subject:: ': 0.39; 'header:Mime-Version:1': 0.39; 'introduced': 0.39; 'to:addr:python.org': 0.39; 'might': 0.40; 'your': 0.61; 'saw': 0.69; 'subject:class': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: A question about class as an iterator Date: Sun, 28 Aug 2011 17:26:11 -0400 References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable 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: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1314566824 news.xs4all.nl 2475 [2001:888:2000:d::a6]:46807 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:12353 On 8/28/2011 1:22 PM, Ya=C5=9Far Arabac=C4=B1 wrote: > I got confused about classes as an iterator. I saw something like this:= > > class foo(): > __iter__(self): > return self > next(self): > return something 2.x > But then I saw a __next__ method on some code. 3.x This might work in 2.6 or .7, but I do not really know. The next() builting was introduced in 2.6 so that *users* could write item =3D next(someiter) and have that work in 2.6+ and in 3.x without change. > which one should I use? Depends on your Python version. I recommend you use 3.2 unless you have=20 a reason or need to use something else. --=20 Terry Jan Reedy