Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #12353 > unrolled thread

Re: A question about class as an iterator

Started byTerry Reedy <tjreedy@udel.edu>
First post2011-08-28 17:26 -0400
Last post2011-08-28 17:26 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: A question about class as an iterator Terry Reedy <tjreedy@udel.edu> - 2011-08-28 17:26 -0400

#12353 — Re: A question about class as an iterator

FromTerry Reedy <tjreedy@udel.edu>
Date2011-08-28 17:26 -0400
SubjectRe: A question about class as an iterator
Message-ID<mailman.516.1314566824.27778.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web