read a file line by line using readline()

Phoe6 orsenthil at gmail.com
Wed Mar 22 13:25:33 EST 2006


Hi all,
I just read the manual and got to know I can use a for loop to iterate
through the lines in the file.

But so far, I was strugling with the following:

import os
file = open('File1.txt','r')
line = file.readline()
while line !=' ':
    print line
    line = file.readline()

As mentioned in the docs, the EOF returns an empty string. I am unable
to catch or match against the EOF. Please help me in pointing out as
where I am making the mistake.


-- 
Senthil
http://phoe6.livejournal.com




More information about the Python-list mailing list