[Python-Dev] Termination of two-arg iter()

Oren Tirosh oren-py-d@hishome.net
Sun, 14 Jul 2002 07:27:45 -0400


On Sun, Jul 14, 2002 at 03:23:25AM -0700, Andrew P. Lentvorski wrote:
> On Sun, 14 Jul 2002, Brett Cannon wrote:
> 
> > end.  It seems like StopIteration is saying "stop please" and
> > IteratorExhausted would be like screaming "STOP CALLING .next()!!!".
> 
> What about raising IndexError by default when someone attempts to call
> .next() on an iterator already raising StopIteration?

+1

IndexError is probably better than inventing a new exception. The description 
of what actually happened would be in the exception text.

StopIteration means "That was the last item, thank you. Sorry I couldn't tell
you my length in advance -- I'm an iterator and I don't even know it myself."

This type of IndexError would mean "Hey, I told you it was the last item. 
This would have been an out-of-bounds index if I were a sequence".

	Oren