[Python-ideas] Add lookahead iterator (peeker) to itertools

Barry Warsaw barry at python.org
Mon Feb 25 22:08:11 CET 2013


On Feb 25, 2013, at 04:20 PM, Oscar Benjamin wrote:

>At times I thought I wanted the ability to query an iterator without
>necessarily popping an element. I've generally found that I ended up
>solving the problem in a different way. My own solution is to have a
>pushable iterator so that after inspecting a value I can push it back
>onto the iterator ready for a subsequent next() call.

The email package has one of these in its feedparser module, called
BufferedSubFile.  It needs to be able to push lines of text back onto the
stack that the normal iteration pops off.

Cheers,
-Barry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130225/68cd81d4/attachment.pgp>


More information about the Python-ideas mailing list