Question about exausted iterators

Christophe chris.cavalaria at
Wed May 17 18:00:56 CEST 2006

Is there a good reason why when you try to take an element from an 
already exausted iterator, it throws StopIteration instead of some other 
exception ? I've lost quite some times already because I was using a lot 
of iterators and I forgot that that specific function parameter was one.

Exemple :

 >>> def f(i):
...     print list(i)
...     print list(i)
 >>> f(iter(range(2)))
[0, 1]

This is using Python 2.4.2

More information about the Python-list mailing list