On 24/08/12 06:35:27, Marco wrote: > Please, can anyone explain me the meaning of the > "buffering > 1" in the built-in open()? > The doc says: "...and an integer > 1 to indicate the size > of a fixed-size chunk buffer." > So I thought this size was the number of bytes or chars, but > it is not
The algorithm is explained at http://docs.python.org/library/io.html#io.DEFAULT_BUFFER_SIZE >> io.DEFAULT_BUFFER_SIZE >> >> An int containing the default buffer size used by the >> module’s buffered I/O classes. open() uses the file’s >> blksize (as obtained by os.stat()) if possible. In other words: open() tries to find a suitable size by calling os.stat(your_file).st_blksize and if that fails, it uses io.DEFAULT_BUFFER_SIZE, which is 8192 on my box. Whether you call open with buffering=2 or any larger number, does not matter: the buffer size will be the outcome of this algorithm. Hope this helps, -- HansM -- http://mail.python.org/mailman/listinfo/python-list