[Tutor] Re: Data format question
project5 at redrival.net
Thu Jul 8 09:04:57 CEST 2004
Kooser, Ara S <askoose <at> sandia.gov> writes:
> I am writing a filter program that reads a column of data, converts it and
then writes it to another file.
> Here is a part of the code for pulling out a column of data and then writing
it to new file.
> inp = open("out.txt","r")outp = open("out2.txt","w")
> for line in inp.readlines(): words = line.split() #thanks to orbitz
for this line if len(words) >= 1: outp.write(words)
Ugh, look at how that code turned out. Are you using a weird mail client?
You've got the code which reads the first column and writes it away already. All
you need to do is process the data before writing it. So instead of writing
words directly, assign it to a variable, then modify that variable in the way
you need it to be modified and finally write it to outp.
More information about the Tutor