[Tutor] Filter question
Alan Gauld
alan.gauld at blueyonder.co.uk
Tue Apr 13 18:54:07 EDT 2004
> def filterFile(lmps, out):
> inp = open("lmps","r")
> outp = open("out","w")
> while 1:
> text = inp.readline()
> if line == "":
> break
> if line[0] == 'I':
> continue
> outp.write(line)
It looks like it should work. You could try a debug print
statement after reading the line, just to check you are
getting the data OK.
Also in 2.3 it might be easier to use a for loop:
def filterFile(filename, outputfile):
inf = file(filename)
outf = file(outputfile, 'w')
for line in inf:
if not line[0] == 'I':
out.write(line) # may need to add \n...
inf.close()
outf.close()
HTH,
Alan G.
More information about the Tutor
mailing list