Newbie: Reading textfiles

Mike Fletcher mfletch at
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:

-----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