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

Scott David Daniels Scott.Daniels at Acm.Org
Tue Jun 16 20:20:48 CEST 2009


MRAB wrote:
> I was thinking along the lines of:
>     def peek(self, size=None, block=True)
> If 'block' is True then return 'size' bytes, unless the end of the
> file/stream is reached; if 'block' is False then return up to 'size'
> bytes, without blocking....

I tend to prefer zero-ish defaults, how about:
     def peek(self, size=None, nonblocking=False)

We still don't have "at most one read" code, but something a bit like

     data = obj.peek(size=desired, nonblocking=True)
     if len(data) < desired:
         data = obj.peek(size=wanted, nonblocking=False)

might suffice.

--Scott David Daniels
Scott.Daniels at Acm.Org




More information about the Python-Dev mailing list