Question about exausted iterators
Roel Schroeven
rschroev_nospam_ml at fastmail.fm
Thu May 18 10:43:14 EDT 2006
Fredrik Lundh schreef:
> Christophe wrote:
>
>>>> Because I'm still waiting for a valid answer to my question.
>>>> The answer "Because it has been coded like that" or is not a
>>>> valid one.
>>> it's been coded like that because that's what the specification
>>> says:
>>>
>>> http://www.python.org/dev/peps/pep-0234/
>> I didn't though I had to mention that "Because the spec has been
>> writen like that" wasn't a valid answer either.
>
> so what is a valid answer?
I think he wants to know why the spec has been written that way.
The rationale mentions exhausted iterators:
"Once a particular iterator object has raised StopIteration, will
it also raise StopIteration on all subsequent next() calls?
Some say that it would be useful to require this, others say
that it is useful to leave this open to individual iterators.
Note that this may require an additional state bit for some
iterator implementations (e.g. function-wrapping iterators).
Resolution: once StopIteration is raised, calling it.next()
continues to raise StopIteration."
This doesn't, however, completey answer the OP's question, I think. It
is about raising or not raising StopIteration on subsequent next() calls
but doesn't say anything on possible alternatives, such as raising
another exception (I believe that's what the OP would like).
Not that I know of use cases for other exceptions after StopIteration;
just clarifying what I think the OP means.
--
If I have been able to see further, it was only because I stood
on the shoulders of giants. -- Isaac Newton
Roel Schroeven
More information about the Python-list
mailing list