[Tutor] read text file in zip archive, process, plot

Andreas Kostyrka andreas at kostyrka.org
Sun Apr 15 20:37:18 CEST 2007


* Kent Johnson <kent37 at tds.net> [070415 20:30]:
> Washakie wrote:
> > Thanks so much! Now another task, associated with this one... what I 
> > actually ultimately want is to just pull out several fields from the 
> > text file in the zip archive (there is actually only one file).. so, my 
> > goal is the to create a file that looks like:
> > 
> > t[0], x[0], y[0]
> > t[1], x[1], y[1]
> > t[2], x[2], y[2]
> > t[3], x[3], y[3]
> > ...
> > t[:], x[:], y[:]
> > 
> > Note, these would actually be strings representing the values... and I'm 
> > not trying to do the header yet... :s
> 
> You could just write them out as you process them. The same loop that 
> reads the input lines can write the output lines.

Consider using the csv module.

out = file("output", "w")
cout = csv.writer(out)
cout.writerow((1,2,3,"abc", "def"))

> > 
> > I've tried OUT = [t,x,y ]
> > but when I write it out, it seems to go through all of t first, then x, 
> > then y...
> > i'm having a really hard time switching my thinking away from matlab 
> > array processing which I think is part of my problem!!

out = file("output", "w")
cout = csv.writer(out)
cout.writerows(zip(t, x, y))
out.close()

Andreas


More information about the Tutor mailing list