I see that you have already accepted an answer, but still, here is my comment. There are a couple of mistakes in your code. The first is that even though you calculate the values correctly, you store them into two variable(q_start
and q_end
) that are not used afterwards.
The second mistake is that you write to the output file the unaltered original data (the lines
list) and do so inside the loop (check your identations). hence, I believe that your output was an N repetition of the original file, where N is the number of lines in it.
The possible thirs mistake is using 'a'
to open the output file. If there was any content in it, it would not be deleted. Since I am not sure of your intentions, this may not be a mistake, but pay attention if you wanted a clean slate or not.
Finally, here is my version of your code, minimally altered to work. I left the 'a'
in the output file open process because I did not know if you did this on purpose.
f=open('w.txt', 'r')
r = open('w2.txt','a')
lines=f.readlines()
for line in lines:
print line
new_list = line.rstrip('\r\n').split(' ')
new_list[1]=str(int(new_list[1]) - 20)
new_list[2]=str(int(new_list[2]) + 20)
r.write('\t'.join(new_list)+"\n")
f.close()
r.close()
I hope this helps.