[Tutor] Iterators, example (need help)
oscar.j.benjamin at gmail.com
Tue Oct 23 03:17:06 CEST 2012
On 23 October 2012 01:43, Steven D'Aprano <steve at pearwood.info> wrote:
> In general, your __iter__ method will be trivially simple:
> def __iter__(self):
> return self
> and most of the logic will be in __next__. I see your __iter__
> method is a little more complicated, but I haven't studied it
> in detail to see if the extra complication is justified.
The __iter__ method performs the same operation that is already
performed in __init__ and __next__ so it is redundant. Probably it
should reset the counter to restart iteration. However, in the
provided code it is never called since the Env instance is never used
in a for loop or iter() call.
More information about the Tutor