How to stop iteration with __iter__() ?

Peter Otten __peter__ at web.de
Wed Aug 20 09:28:19 EDT 2008


MRAB wrote:

> So it's defined behaviour that an exhausted iterable will always raise
> StopIteration no matter how many times it's asked for the next value?

That is not enforced. However, quoting
http://www.python.org/dev/peps/pep-0234/

"""
Iterator implementations (in C or in Python) should guarantee that
once the iterator has signalled its exhaustion, subsequent calls
to tp_iternext or to the next() method will continue to do so.
"""

Peter



More information about the Python-list mailing list