On Sep 21, 10:13 pm, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > According to the Python docs, once an iterator raises StopIteration, it > should continue to raise StopIteration forever. Iterators that fail to > behave in this fashion are deemed to be "broken": > > http://docs.python.org/lib/typeiter.html > > I don't understand the reasoning behind this. As I understand it, an > iterator is something like a stream. There's no constraint that once a > stream is empty it must remain empty forever.
I think empty != StopIteration. StopIteration (IMHO) shouldn't be raised when the stream is empty, instead a sentinel value specifying that "there is no data yet, but if you wait there might be" should be returned (possibly None or empty string). When you raise StopIteration, it is a signal that I don't have any more data and there is no use in waiting. > Can somebody explain why "broken iterators" are broken? > > -- > Steven -- http://mail.python.org/mailman/listinfo/python-list