Newbie: Reading textfiles

Mike Fletcher mfletch at tpresence.com
Wed Mar 1 19:00:57 CET 2000


First approach:

file = open( filename )
line = file.readline()
while line:
	doprocessing( line )
	line = file.readline()


Second approach:

import fileinput
file = fileinput.FileInput( filename )
for line in file:
	doprocessing(line)

HTH,
Mike
-----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

-- 
http://www.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list