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

Lucas P Melo lukepadawan at gmail.com
Tue Jun 16 15:10:40 CEST 2009

Cameron Simpson wrote:
> Indeed, though arguably read1() is a lousy name too, on the same basis.
> My itch is that peek() _feels_ like it should be "look into the buffer"
> but actually can block and/or change the buffer.
I guess all the buffer operations should be transparent to the user if 
he wants it to be like that, since not so many people want to have a 
tight control over this kind of detail.
I think of peek() as an operation that allows me to peek what's going to 
show up in the future without affecting further read()s. This kind of 
behavior is expected by users without prior knowledge of the inner 
workings of buffered IO.

So, if an user _really_ wants to take a look at what's to come without 
affecting the buffer, we could allow that by doing something like this:
peek(5, change_buffer=False)
This is an alternative to the peek0(). But I am ok wih the peek0() too.

More information about the Python-Dev mailing list