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.
-- http://mail.python.org/mailman/listinfo/python-list