Question about the built-in file() and buffer size...

Darby Wong at
Thu Feb 5 00:14:23 CET 2004

The documentation for file() says that the buffer size will be:

system default if bufsize == -1, 
unbuffered if bufsize == 0, 
line buffered if bufsize == 1, 
or else it is just bufsize.

I can't get this last one to work... if I write something like:

>>> test = file("testfile","w",1024)
>>> test.write("a"*1025);

the file "testfile" is not written to... it only gets written to when
the buffer size reaches 4096 bytes, which is the system default from
what I can ascertain.  It doesn't work if I set bufsize to be larger
than 4096 either, it will get written when it reaches 4096 bytes no
matter what.

Am I doing something wrong?  Is this option not implemented all the
way (the -1,0,1 seem to work fine... except that 1 is also 4096 byte
buffered, in addition to being line buffered)?

Thanks :)

More information about the Python-list mailing list