Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #5170

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

Path csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!feeder.news-service.com!85.214.198.2.MISMATCH!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From "Martin P. Hellwig" <martin.hellwig@gmail.com>
Newsgroups comp.lang.python
Subject Re: py3k buffered IO - flush() required between read/write?
Date Wed, 11 May 2011 23:24:46 +0000
Organization A noiseless patient Spider
Lines 50
Message-ID <iqf2bd$9n2$1@dont-email.me> (permalink)
References <iqedg8$k5a$7@dont-email.me> <mailman.1422.1305138322.9059.python-list@python.org> <iqemrg$jp4$1@dont-email.me>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 8bit
Injection-Date Wed, 11 May 2011 22:24:45 +0000 (UTC)
Injection-Info mx02.eternal-september.org; posting-host="DryjObO1+zXLpKq2ViMFlg"; logging-data="9954"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18c76GuC7CKOM8Lp8KT3lKf"
User-Agent Mozilla/5.0 (X11; U; FreeBSD amd64; en-US; rv:1.9.2.13) Gecko/20110301 Thunderbird/3.1.7
In-Reply-To <iqemrg$jp4$1@dont-email.me>
Cancel-Lock sha1:OLW+8+9NatQisw0IJzyF9FvXNlM=
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:5170

Show key headers only | View raw


On 11/05/2011 19:08, 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
>
> All the best,
>
> -eg.

from:
http://docs.python.org/py3k/library/functions.html#open
"""
open(file, mode='r', buffering=-1, encoding=None, errors=None, 
newline=None, closefd=True)¶
<cut>
buffering is an optional integer used to set the buffering policy. Pass 
0 to switch buffering off (only allowed in binary mode), 1 to select 
line buffering (only usable in text mode), and an integer > 1 to 
indicate the size of a fixed-size chunk buffer. When no buffering 
argument is given, the default buffering policy works as follows:

     * Binary files are buffered in fixed-size chunks; the size of the 
buffer is chosen using a heuristic trying to determine the underlying 
device’s “block size” and falling back on io.DEFAULT_BUFFER_SIZE. On 
many systems, the buffer will typically be 4096 or 8192 bytes long.
     * “Interactive” text files (files for which isatty() returns True) 
use line buffering. Other text files use the policy described above for 
binary files.
"""

So given that explanation, and assuming I understand it, I go for option 
'iii'.

-- 
mph

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

py3k buffered IO - flush() required between read/write? Genstein <genstein@invalid.invalid> - 2011-05-11 17:27 +0100
  Re: py3k buffered IO - flush() required between read/write? Terry Reedy <tjreedy@udel.edu> - 2011-05-11 14:24 -0400
    Re: py3k buffered IO - flush() required between read/write? Genstein <genstein@invalid.invalid> - 2011-05-11 20:08 +0100
      Re: py3k buffered IO - flush() required between read/write? Terry Reedy <tjreedy@udel.edu> - 2011-05-11 17:38 -0400
        Re: py3k buffered IO - flush() required between read/write? Genstein <genstein@invalid.invalid> - 2011-05-12 14:30 +0100
          Re: py3k buffered IO - flush() required between read/write? Terry Reedy <tjreedy@udel.edu> - 2011-05-12 15:44 -0400
            Re: py3k buffered IO - flush() required between read/write? Genstein <genstein@invalid.invalid> - 2011-05-12 21:38 +0100
      Re: py3k buffered IO - flush() required between read/write? "Martin P. Hellwig" <martin.hellwig@gmail.com> - 2011-05-11 23:24 +0000

csiph-web