Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed3a.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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'explicitly': 0.05; 'rename': 0.07; 'next,': 0.09; 'noted,': 0.09; 'cc:addr:python- list': 0.11; 'python': 0.11; 'def': 0.12; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'intended.': 0.16; 'renaming': 0.16; 'subclass': 0.16; 'subject:generator': 0.16; 'typeerror:': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'written': 0.21; 'import': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'cc:2**0': 0.24; 'subject:/': 0.26; '2010,': 0.27; 'van': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'dec': 0.30; 'message- id:@mail.gmail.com': 0.30; '"",': 0.31; '>>>>': 0.31; 'object.': 0.31; 'file': 0.32; 'class': 0.32; 'probably': 0.32; 'run': 0.32; '(most': 0.33; 'skip:_ 10': 0.34; 'received:google.com': 0.35; 'method': 0.36; 'skip:- 20': 0.37; 'recent': 0.39; 'break': 0.61; 'more': 0.64; 'note:': 0.66; '2015': 0.84; 'albert': 0.91; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=qvmq2QgMfPMXaJftGDNCFlZ/Uea7b4D8QLzDtOmmLLg=; b=HJ5GrLBUPdHbzLjjy6bp1G+hD0Tw7mqVea3Or2HHHteVKtUh4TvMTv3+0xT/6zMuum hcdyxlVzxzZFBnekrpHag60WWXlSFvB/AwECtHal5e3DYV5R9XWUb9QEKij85JgIfLlA 8aViVYiU/nW/CspqF196UXcNDyi8Ei1XAsKrO4NSqf8U8PgeJFIal9jVP7vYHdkjBVTr 9zLjFG0nn/MG9vmHGyw3o4y6apBL/0D4LpDl/OFRQx3PPBdH5qyHpWFb/hGqjO+FITMp FqeSMPG06gVjgnv2rVG1myhO9+MqGE4Bsyn8+4dNW2YYuu7uQFQQBCXl38wZ1lVIQ06L UpUw== MIME-Version: 1.0 X-Received: by 10.50.29.109 with SMTP id j13mr5254600igh.2.1427816210883; Tue, 31 Mar 2015 08:36:50 -0700 (PDT) In-Reply-To: <551ab739$0$3042$e4fe514c@dreader35.news.xs4all.nl> References: <55062bda$0$12998$c3e8da3$5496439d@news.astraweb.com> <551a9ebe$0$2987$e4fe514c@dreader35.news.xs4all.nl> <551ab739$0$3042$e4fe514c@dreader35.news.xs4all.nl> Date: Wed, 1 Apr 2015 02:36:50 +1100 Subject: Re: generator/coroutine terminology From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.19 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: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1427816214 news.xs4all.nl 2962 [2001:888:2000:d::a6]:53834 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:88391 On Wed, Apr 1, 2015 at 2:03 AM, Albert van der Horst wrote: > class Squares: > def __init__(self): > self.i = 0 > def __next__(self): > self.i += 1 > return self.i**2 > def __iter__(self): > return self > > albert@cherry:/tmp$ python > Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48) > [GCC 4.4.5] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> from aap import * >>>> for i in Squares(): > ... print i > ... if i>50: break > ... > Traceback (most recent call last): > File "", line 1, in > TypeError: instance has no next() method >>>> > > / -------------------------- > > Probably not what is intended. > > Last minute note: > renaming __next__() into next() did the job. That class was written for Python 3, not Python 2. In Py2, you need to rename __next__ to next, as you noted, and you probably also want to explicitly subclass object. Or just run it under Python 3. :) ChrisA