Newbie: Reading textfiles
Stidolph, David
stidolph at origin.ea.com
Wed Mar 1 13:02:52 EST 2000
Try this:
f = open(filename,"rt")
f.seek(0,2) #seek to end
size = f.tell()
f.seek(0,0) #seek back to beginning
while f.tell() < size:
line = f.readline()
# do something with line
f.close()
Remember, there will be a cr or cr/lf at the end of each line.
Good luck.
David Stidolph
Origin
-----Original Message-----
From: Lutz.Schroeer at altavista.net [mailto:Lutz.Schroeer at altavista.net]
Sent: Wednesday, March 01, 2000 11:18 AM
To: python-list at python.org
Subject: Newbie: Reading textfiles
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
--
http://www.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list