Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #12353
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: A question about class as an iterator |
| Date | 2011-08-28 17:26 -0400 |
| References | <CAFEUn8beiwB+GJJAhT+J9E+TsZFYdudwPBg3as+qAoYVB2RVUg@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.516.1314566824.27778.python-list@python.org> (permalink) |
On 8/28/2011 1:22 PM, Yaşar Arabacı 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 = 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 a reason or need to use something else. -- Terry Jan Reedy
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: A question about class as an iterator Terry Reedy <tjreedy@udel.edu> - 2011-08-28 17:26 -0400
csiph-web