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 :
[color=blue][color=green][color=darkred]
>>> def f(i):[/color][/color][/color]
.... print list(i)
.... print list(i)
....[color=blue][color=green][color=darkred]
>>> f(iter(range(2) ))[/color][/color][/color]
[0, 1]
[][color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
This is using Python 2.4.2
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 :
[color=blue][color=green][color=darkred]
>>> def f(i):[/color][/color][/color]
.... print list(i)
.... print list(i)
....[color=blue][color=green][color=darkred]
>>> f(iter(range(2) ))[/color][/color][/color]
[0, 1]
[][color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
This is using Python 2.4.2
Comment