On Tue, Jun 17, 2008 at 1:46 AM, Christopher Spears <[EMAIL PROTECTED]> wrote:
> I am confused by this statement: >>>> i = iter(a) > > Why do I need to turn 'a' into an iterator? Didn't I already do this when I > constructed the class? Yes, a is already an iterator. > As a test, I tried the following: > >>>> for j in range(1,5): > ... print j, ':', a.next(j) > ... > 1 : > Traceback (most recent call last): > File "<stdin>", line 2, in ? > File "<stdin>", line 13, in next > StopIteration >>>> > > Why didn't that work? Did you make a new a or reuse the same one? The old a has reached the end of its values so it raises StopIteration. Note that passing parameters to next() is not part of the iterator protocol. Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor