readline in while loop
Gerhard Häring
gh at ghaering.de
Fri May 23 08:40:55 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;
> [...]
Not sure what your problem is. But I'd suggest you just iterate over the file,
line by line:
f = file("test.txt")
for line in f:
line = line.strip()
...
f.close()
-- Gerhard
More information about the Python-list
mailing list