[Python-ideas] sentinel_exception argument to `iter`

Stefan Behnel stefan_ml at behnel.de
Sat Feb 8 09:28:15 CET 2014


Terry Reedy, 08.02.2014 08:32:
> iter(iter_or_call, sentinel=<private object>, stop_iter=<private exception>)
> is still my current proposal.

+1, the name "stop_iter" resembles StopIteration, which IMHO is enough of a
hint at what it does.

Also, +1 for the general proposal. While I'd rarely use either of the two,
my guess is that there aren't even as many use cases for iterating up to a
sentinel value (and I used that already) as for iterating up to an
exception (and I'm sure I would have used that as well, if it had been there).


> Serhiy suggested 'stop_iter=StopIteration'
> and I will explain separately why I think that this would not work.

It suggests that it swallows a raised StopIteration *instance* and raises
its own, which it shouldn't.

Stefan




More information about the Python-ideas mailing list