stdio EOF ?

Erik Max Francis max at alcyone.com
Fri Aug 9 18:34:37 EDT 2002


François Pinard wrote:

> I did not read the thread.  I merely replied to the message saying
> that:
> 
> > > > The standard idiom [...] is:
	...

Note that the part you elided here was "for this," not "for reading a
file in general."  I was talking about the standard idiot for doing
interactive line-by-line reading.

> As long as you keep to a single "for line in file.xreadlines():" or
> "for line in file:", is there a problem associated with the buffering?
> I'm merely curious, here...

It is not necessarily a problem, unless you want line-by-line
interactivity.  In 

	for line in file.readlines():
	    ...

all of the lines are read in at once and then iterated over.  This means
that you have to wait for the entire input file to finish before any
processing starts.  With 

	for line in file.xreadlines():
	    ...

the .xreadlines method returns a special object which acts the same way
but reads the file in chunks -- but still not line by line.  If you want
line-by-line interactively, these mechanics are not what you want.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ There is nothing so subject to the inconstancy of fortune as war.
\__/ Miguel de Cervantes
    Church / http://www.alcyone.com/pyos/church/
 A lambda calculus explorer in Python.



More information about the Python-list mailing list