Generating text files (newbie)
Doran, Harold
HDoran at air.org
Thu Dec 28 08:59:25 EST 2006
Assume I have a tab-delimited text file called foo.txt organized as
follows:
x11 -0.04
x22 -0.42
x33 0.3
My goal is to read in this file and use the information therein to
output a new file that is organized as follows:
x11 IRM=3PL IPB= -0.04
x22 IRM=3PL IPB= -0.42
x33 IRM=3PL IPB= 0.3
I am a newbie with python and am trying to put the pieces together. Now,
I know if I had a list, I could do something like:
a = [-0.04, -0.42, 0.3]
>>> for i in a:
print "IRM = 3PL", "\t", "IPB = ", i
IRM = 3PL IPB = -0.04
IRM = 3PL IPB = -0.42
IRM = 3PL IPB = 0.3
And then I could write this to a file. But I am not sure how to I might
tackle this when I read in a text file.
So far, my basic skills allow for me to accomplish the following
# read in file
params = open('foo.txt', 'r+')
# Write to the file
params.write('Add in some new test\n')
params.close()
Any pointers are appreciated. I'm using python 2.3 on a windows xp
machine.
Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20061228/dee0621a/attachment.html>
More information about the Python-list
mailing list