Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #85430
| References | (1 earlier) <54d94307$0$12998$c3e8da3$5496439d@news.astraweb.com> <CALwzidnufuFPX1K0QrAJZbEtS79xvOmhM7ZZ8t9dJSiKVvhUqQ@mail.gmail.com> <54D98A35.9060203@earthlink.net> <CAPTjJmrcbOYCuZCgiq9gStEG34nAvQ2gS-vZC-WUuAOPUV3hPw@mail.gmail.com> <54D9A22E.2070708@earthlink.net> |
|---|---|
| Date | 2015-02-10 17:38 +1100 |
| Subject | Re: __next__ and StopIteration |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.18597.1423550718.18130.python-list@python.org> (permalink) |
On Tue, Feb 10, 2015 at 5:16 PM, Charles Hixson <charleshixsn@earthlink.net> 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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
__next__ and StopIteration Charles Hixson <charleshixsn@earthlink.net> - 2015-02-09 11:14 -0800
Re: __next__ and StopIteration Rob Gaddi <rgaddi@technologyhighland.invalid> - 2015-02-09 19:27 +0000
Re: __next__ and StopIteration Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-02-10 10:30 +1100
Re: __next__ and StopIteration Ian Kelly <ian.g.kelly@gmail.com> - 2015-02-09 16:56 -0700
Re: __next__ and StopIteration Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-02-10 11:42 +1100
Re: __next__ and StopIteration Chris Angelico <rosuav@gmail.com> - 2015-02-10 11:54 +1100
Re: __next__ and StopIteration Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-02-10 12:11 +1100
Re: __next__ and StopIteration Chris Angelico <rosuav@gmail.com> - 2015-02-10 12:58 +1100
Re: __next__ and StopIteration Chris Kaynor <ckaynor@zindagigames.com> - 2015-02-09 16:59 -0800
Re: __next__ and StopIteration Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-02-10 16:54 +1100
Re: __next__ and StopIteration Ian Kelly <ian.g.kelly@gmail.com> - 2015-02-10 01:30 -0700
Re: __next__ and StopIteration Chris Kaynor <ckaynor@zindagigames.com> - 2015-02-10 09:27 -0800
Re: __next__ and StopIteration Charles Hixson <charleshixsn@earthlink.net> - 2015-02-09 20:33 -0800
Re: __next__ and StopIteration Chris Angelico <rosuav@gmail.com> - 2015-02-10 15:46 +1100
Re: __next__ and StopIteration Charles Hixson <charleshixsn@earthlink.net> - 2015-02-09 22:16 -0800
Re: __next__ and StopIteration Chris Angelico <rosuav@gmail.com> - 2015-02-10 17:38 +1100
Re: __next__ and StopIteration Ethan Furman <ethan@stoneleaf.us> - 2015-02-10 08:44 -0800
Re: __next__ and StopIteration Ian Kelly <ian.g.kelly@gmail.com> - 2015-02-10 09:53 -0700
Re: __next__ and StopIteration Ethan Furman <ethan@stoneleaf.us> - 2015-02-10 09:33 -0800
csiph-web