[Tutor] Re: Data format question

Andrei 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. 
<snip>
> 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[0])  

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[0] 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.

Yours,

Andrei



More information about the Tutor mailing list