Newbie: Reading textfiles

Steve Holden sholden at bellatlantic.net
Wed Mar 1 12:44:11 EST 2000


The first call to readline() which returns an empty string indicates
you have hit the end of the file.  Empty lines in the file are
returned as strings with the newline still in them.  Don't forget
that every line you actually read has the newline in it, too!

Unless the files are too large to consider this, the readlines() file
method is easier to use.  But you've probably already rejected this by
the way you state your question.

regards
 Steve

"Lutz Schröer" wrote:
> 
> Hi,
> 
> after looking for a"clever" solution for reading a text file line by line
> from the beginning to the end for the whole day, I have to ask this
> ridiculous newbie question:
> 
> How do I read a textfile line by line and catch the eof?
> 
> Latz

--
"If computing ever stops being fun, I'll stop doing it"



More information about the Python-list mailing list