Exception handling in Python 3.x

MRAB python at mrabarnett.plus.com
Mon Dec 6 19:48:30 EST 2010


On 07/12/2010 00:23, Steven D'Aprano wrote:
> On Mon, 06 Dec 2010 13:13:40 -0800, Paul Rubin wrote:
>
>> It's really unfortunate, though, that Python 3 didn't offer a way to
>> peek at the next element of an iterable and test emptiness directly.
>
> This idea of peekable iterables just won't die, despite the obvious flaws
> in the idea.
>
> There's no general way of telling whether or not a lazy sequence is done
> except to actually generate the next value, and caching that value is not
> appropriate for all such sequences since it could depend on factors which
> have changed between the call to peek and the call to next.
>
> If you want to implement a peek method in your own iterables, go right
> ahead. But you can't make arbitrary iterables peekable without making a
> significant class of them buggy.
>
Perhaps Python could use Guido's time machine to check whether the
sequence will yield another object in the future. :-)



More information about the Python-list mailing list