Built-in open() with buffering > 1

Ramchandra Apte maniandram01 at gmail.com
Fri Aug 24 10:32:52 EDT 2012


`f._CHUNK_SIZE = 5` is modifying Python's internal variables - don't do that
google buffering to find out what it is
buffering is how much Python will keep in memory
f.read(1) will actually read `buffering` bytes of memory so that when you read later, the reading can be done from memory
On Friday, 24 August 2012 10:51:36 UTC+5:30, Marco  wrote:
> On 08/24/2012 06:35 AM, 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."
> 
> 
> 
> Sorry, I get it:
> 
> 
> 
>  >>> f = open('myfile', 'w', buffering=2)
> 
>  >>> f._CHUNK_SIZE = 5
> 
>  >>> for i in range(6):
> 
> ...     n = f.write(str(i))
> 
> ...     print(i, open('myfile').read(), sep=':')
> 
> ...
> 
> 0:
> 
> 1:
> 
> 2:
> 
> 3:
> 
> 4:
> 
> 5:012345




More information about the Python-list mailing list