Why are "broken iterators" broken?

Craig Allen callen314 at gmail.com
Tue Sep 23 23:28:00 CEST 2008


I'm interested what others think of this because at first I couldn't
get it... I have an object which can iterate over its parts... and at
first I thought, what? I'm supposed to create a new object every time
the user needs to iterate the contents?

In the end I interpreted that statement as if "unless __iter__()" is
called again, in which case it makes sense that an iterator should
stay "finished" until it's told to start to iterate again.

Then even the stream analogy holds, you don't expect a stream to say
EOF then start giving you bytes (from beyond the end, I guess)...
instead, such a stream would more likely block if it got to the end of
available data.

I'm probably being stupid in this... perhaps I'm the only one that at
first interpreted the phrase as being regardless of a fresh call to
__iter__()... and that the OP was worried about some other
implication.  But if I was wrong to think it's ok for one and the same
iterator to reset when __iter__() is called again, then I seriously
don't understand.

what does "forever" mean in that dictum?



More information about the Python-list mailing list