[Tutor] Printing columns of data
Bob Gailer
bgailer at alum.rpi.edu
Tue Feb 8 21:57:33 CET 2005
At 01:03 PM 2/8/2005, Kooser, Ara S wrote:
>Content-class: urn:content-classes:message
>Content-Type: multipart/alternative;
> boundary="----_=_NextPart_001_01C50E19.4E45912A"
>
>Hello all,
>
> I am writing a program to take a data file, divide it up into columns
> and print the information back with headers. The data files looks like this
>
> 0.0 -3093.44908 -3084.59762 387.64329 26.38518 0.3902434E+00
> -0.6024320E-04 0.4529416E-05
> 1.0 -3094.09209 -3084.52987 391.42288 105.55994 0.3889897E+00
> -0.2290866E-03 0.4187074E-03
> 2.0 -3094.59358 -3084.88826 373.64911 173.44885 0.3862430E+00
> -0.4953443E-03 0.2383621E-02
> etc
> 10.0 ...
>
>So I wrote the program included below and it only prints the last line of
>the file.
>
>Timestep PE
>10.0 -3091.80609
>
>I have one question. Do I need to put ts and pe into a list before I print
>then to screen or I am just missing something. Thanks.
>
>Ara
>
>import string
>
>inp = open("fort.44","r")
>all_file = inp.readlines()
>inp.close()
>
>outp = open("out.txt","w")
>
>cols = map(string.split,all_file)
>##print cols
>
>Data = {}
>for line in cols:
> ts = line[0]
># print line[0]
> pe = line[1]
># print line[1]
>
>print """
>
>Timestep PE"""
>print "%s %s " % (ts,pe)
>
>outp.close()
Put the print statement in the for loop.
for line in cols:
...
print "%s %s " % (ts,pe)
Bob Gailer
mailto:bgailer at alum.rpi.edu
303 442 2625 home
720 938 2625 cell
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050208/03a98ee6/attachment.htm
More information about the Tutor
mailing list