[Tutor] iter class

Keith Winston keithwins at gmail.com
Thu Jan 23 20:24:20 CET 2014


On Thu, Jan 23, 2014 at 7:05 AM, eryksun <eryksun at gmail.com> wrote:
> Generally you'll make `__iter__` a generator, so you don't have to
> worry about implementing `__next__`. Also, the built-in function
> `next` was added in 2.6, so you don't have to worry about the method
> name difference between 2.x and 3.x, either.

I'm now realizing I don't understand this comment at all. First, there
IS a __iter__ method in the example: does the presence of such make it
a generator already, or is it a usage thing, or something else? I
don't yet completely understand the difference/point... or maybe you
mean inherit the generator class?

Second: you state that I don't have to worry about the name
difference, but when I changed the method name from next to __next__
it worked in 3.3. So what's your point here?

I'm just realizing I'm missing your pearls of wisdom, not intending on
being combative or something.
-- 
Keith


More information about the Tutor mailing list