py3k buffered IO - flush() required between read/write?

Terry Reedy tjreedy at udel.edu
Wed May 11 17:38:26 EDT 2011


On 5/11/2011 3:08 PM, Genstein wrote:
> On 11/05/2011 19:24, Terry Reedy wrote:
>> writing and reading. If you want others to look at this more, you should
>> 1) produce a minimal* example that demonstrates the questionable
>> behavior, and 2) show the comparative outputs that raise your question.
>
> Thanks for a quick response. Perhaps I was being unclear - in py3k,
> given the following code and assuming no errors arise:
>
>  > f = open("foo", "w+b")
>  > f.write(b'test')
>  > f.seek(0)
>  > print(f.read(4))
>
> What is the printed result supposed to be?
>
> i) b'test'
> ii) never b'test'
> iii) platform dependent/undefined/other

Good clear question. I expect i).

With 3.2 on winxp, that is what I get with StringIO, text file, and 
bytes file (the first two with b's removed). I would expect the same on 
any system. If you get anything different, I would consider it a bug

-- 
Terry Jan Reedy




More information about the Python-list mailing list