[Python-Dev] io.BufferedReader.peek() Behaviour in python3.1

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Jun 14 02:33:35 CEST 2009


Antoine Pitrou wrote:
> The original docstring for peek() says:
> 
>         ...we
>         do at most one raw read to satisfy it.
> 
> In that light, I'm not sure it's a bug

It may be behaving according to the docs, but is that
behaviour useful?

Seems to me that if you're asking for n bytes, then it's
because you're doing some kind of parsing that requires
lookahead, and nothing less than n bytes will do.

I think it would be more useful if the "at most one
raw read" part were dropped. That would give it the
kind of deterministic behaviour generally expected
when dealing with buffered streams.

-- 
Greg


More information about the Python-Dev mailing list