Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2a.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.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'class,': 0.07; 'function,': 0.09; 'grid': 0.09; 'iterate': 0.09; 'rows': 0.09; 'cc:addr:python-list': 0.11; 'charles': 0.16; 'factory': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'iterator': 0.16; 'iterator,': 0.16; 'objects.': 0.16; 'once.': 0.16; 'wrote:': 0.18; 'properly': 0.19; 'feb': 0.22; 'cc:addr:python.org': 0.22; 'apply.': 0.24; 'cc:2**0': 0.24; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'included': 0.31; 'formed': 0.31; 'once,': 0.31; 'class': 0.32; "i'd": 0.34; "can't": 0.35; 'something': 0.35; 'form.': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'pm,': 0.38; 'rather': 0.38; 'new': 0.61; "you're": 0.61; 'back': 0.62; 'more': 0.64; 'brand': 0.72; '2015': 0.84; 'cycled': 0.84; 'subject:skip:S 10': 0.84; '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=Mw5rAT1Vk9UEvFcMezpmsnZVNNf7l0cKZHv1Rc1MuFk=; b=D0/yrxP8PcE2oxBVK4sIeaLFXIpeDNmE8qOxULoSmjtC8Q3QMazJUsgfClXjvJHOiQ iEKLaRLiwNrhk2llU/hWcPMAM7zMVu4lScS/fs52XiJWOiFWDOapF537A+/P0z9o3w0D Knm42sM6SI6IkbShl6IawUdGfELOVoButQb1vkZvdvoxTKkz5o5DK4LA5l51vLwjjyEb x+whkoDwftJbU4/sNOM3zzjucVbGYzijfMLrf9rAB+FtI/rB91WKSKGGEQ9MC8MDiLRz Fe6bAvXNxJg5lFv4hDXYHIFEFCbbODvx6iN/eDvQWD0z3JwegGiqebmOLZ4gKaigeHzm j2nQ== MIME-Version: 1.0 X-Received: by 10.50.171.201 with SMTP id aw9mr21740843igc.2.1423550332997; Mon, 09 Feb 2015 22:38:52 -0800 (PST) In-Reply-To: <54D9A22E.2070708@earthlink.net> References: <54d94307$0$12998$c3e8da3$5496439d@news.astraweb.com> <54D98A35.9060203@earthlink.net> <54D9A22E.2070708@earthlink.net> Date: Tue, 10 Feb 2015 17:38:52 +1100 Subject: Re: __next__ and StopIteration 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.15 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: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1423550718 news.xs4all.nl 2867 [2001:888:2000:d::a6]:34166 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:85430 On Tue, Feb 10, 2015 at 5:16 PM, Charles Hixson wrote: > Yes, rows and cols are lists, but I'm going to need to iterate through them > more than once. I'd rather do without a included class, but if a properly > formed iterator can only be cycled through once, and if I understand > properly that means I can't use the "class instance is it's own iterator" > form. When you write __iter__ as a generator function, what you actually have is a factory for iterator objects. (Generators are iterators.) When something calls __iter__ on your Grid, it gets back a brand new iterator which is independent of every other iterator from that or any other Grid, so you can iterate over the same Grid more than once. You're not writing __next__ here, so you're not using the class instance as its own iterator, which means that that consideration doesn't apply. ChrisA