How to stop iteration with __iter__() ?

Peter Otten __peter__ at
Wed Aug 20 15:28:19 CEST 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

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.


More information about the Python-list mailing list