eof?
Jeff Shannon
jeff at ccvcorp.com
Wed Aug 15 14:08:44 EDT 2001
Chris Barker wrote:
> Alex Martelli wrote:
>
> > There are several ways. Best overall, today (Python 2.1):
> >
> > for line in fh.xreadlines():
> > process(line)
>
> or, if processing the file as a list of lines doesn't work, the standard
> idiom is:
>
> fh = open("file", "r")
> while 1:
> line = fh.readline()
> if not line: break
> # do stuff with line
>
Maybe I'm just being clueless here, but in what way is this semantically
different from Alex's suggestion? In each case, you are producing a single
line at a time, then processing that line. Admittedly, if Alex wasn't using
xreadlines() instead of the "regular" readlines(), then you have the
overhead of reading the entire file and building the list up front, but...
as is, I don't see the difference. (Excepting that the for loop is much
more concise, readable and intuitively understandable.)
Jeff Shannon
Technician/Programmer
Credit International
More information about the Python-list
mailing list