Built-in open() with buffering > 1

Marco marco_u at nsgmail.com
Fri Aug 24 00:35:27 EDT 2012


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:

 >>> f = open('myfile', 'w', buffering=2)
 >>> f.write('a')
1
 >>> open('myfile').read()
''
 >>> f.write('b')
1
 >>> open('myfile').read()
''
 >>> f.write('cdefghi\n')
8
 >>> open('myfile').read()
''
 >>> f.flush()
 >>> open('myfile').read()
'abcdefghi\n'

Regards,
Marco



More information about the Python-list mailing list