Possible File iteration bug
tjreedy at udel.edu
Fri Jul 15 23:45:27 CEST 2011
On 7/15/2011 8:26 AM, Billy Mays wrote:
> On 07/15/2011 04:01 AM, bruno.desthuilliers at gmail.com wrote:
>> On Jul 14, 9:46 pm, Billy Mays<no... at nohow.com> wrote:
>>> I noticed that if a file is being continuously written to, the file
>>> generator does not notice it:
>>> def getLines(f):
>>> lines = 
>>> for line in f:
>>> return lines
>> what's wrong with file.readlines() ?
> Using that will read the entire file into memory which may not be
So will getLines.
> possible. In the library reference, it mentions that using the generator
> (which calls file.next()) uses a read ahead buffer to efficiently loop
> over the file. If I call .readline() myself, I forfeit that performance
Are you sure? Have you measured the difference?
Terry Jan Reedy
More information about the Python-list