Newbie: Reading textfiles

Stidolph, David stidolph at
Wed Mar 1 19:02:52 CET 2000

Try this:

f = open(filename,"rt"),2) #seek to end
size = f.tell(),0) #seek back to beginning
while f.tell() < size:
  line = f.readline()
  # do something with line

Remember, there will be a cr or cr/lf at the end of each line.

Good luck.

David Stidolph

-----Original Message-----
From: Lutz.Schroeer at [mailto:Lutz.Schroeer at]
Sent: Wednesday, March 01, 2000 11:18 AM
To: python-list at
Subject: Newbie: Reading textfiles


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?


More information about the Python-list mailing list