readline in while loop

Steve Holden sholden at holdenweb.com
Fri May 23 09:18:38 EDT 2003


"Geert Fannes" <geert.fannes at esat.kuleuven.ac.be> wrote..
> hello, i tried to construct a program to read a file, line after line. i
> have no idea why it does not work...
>
> f=file("test.txt","r");
> while l=f.readline():
> print l;
>
> the problem is with "while l=f.readline():" the next program does work
>
> f=file("test.txt","r");
> while f.readline():
>
> i tried things like
>
> f=file("test.txt","r");
> while (l=f.readline())!="":
> print l;
>
> but that doesn't work either. just reading the lines is not enough, i
> want to do something with the read lines.
>

http://www.python.org/cgi-bin/faqw.py?req=show&file=faq06.030.htp

regards
--
Steve Holden                                  http://www.holdenweb.com/
Python Web Programming                 http://pydish.holdenweb.com/pwp/







More information about the Python-list mailing list