eof?
Peter Hansen
peter at engcorp.com
Tue Aug 14 19:49:29 EDT 2001
Chris Barker wrote:
> [...]
> 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
>
> I'm not really very fond of "while 1" constructs, but since the break is
> right there next to it, it's not too bad, and I think a little better
> than what I used to do:
>
> fh = open("file", "r")
> line = fh.readline()
> while 1:
> # do stuff with line
> # there could be a LOT of code here
>
> line = fh.readline()
Definitely better than what you used to do, since your code
wouldn't exit. Or was that the point? :)
--
----------------------
Peter Hansen, P.Eng.
peter at engcorp.com
More information about the Python-list
mailing list