On 2007-01-10, Steven Bethard <[EMAIL PROTECTED]> wrote:
> Neil Cerutti wrote:
>> For use in a hand-coded parser I wrote the following simple
>> iterator with look-ahead.
>
> There's a recipe for this:
>
>    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/304373
>
> Note that the recipe efficiently supports an arbitrary
> look-ahead, not just a single item.
>
>> I haven't thought too deeply about what peek ought to return
>> when the iterator is exhausted. Suggestions are respectfully
>> requested.
>
> In the recipe, StopIteration is still raised on a peek()
> operation that tries to look past the end of the iterator.

That was all I could think of as an alternative, but that makes
it fairly inconvenient to use. I guess another idea might be to
allow user to provide a "no peek" return value in the
constructor, if they so wish.

-- 
Neil Cerutti
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to