[Tutor] Filtering text files
Alan Gauld
alan.gauld at blueyonder.co.uk
Thu Apr 15 14:05:02 EDT 2004
> statement and then a out.txt is created but is blank. I am guessing
that
> something is wrong with my write command. Thanks again.
>
> Ara
>
> def filterFile(lmps,out):
> inp = open("lmps.txt", "r")
> outp = open("out.txt", "w")
> while 1:
> text = inp.readline()
> if text =="":
> break
> if text[0] =="I":
> continue
> outp.write(text)
This is outside the loop so only the last line gets printed,
but the last line is ""!
You need to move the write inside the loop.
Alan G.
More information about the Tutor
mailing list