I have been stuck in this problem for hours now. I have a txt file where the following is the contents.
10 0.4600 0.4833 0.0433 0.0833
4 0.7833 0.6350 0.1167 0.0933
7 0.3583 0.4933 0.1667 0.1700
I'm trying to subtract 1 on the first numbers of the content to achieve the following result while maintaining the floating point numbers:
9 0.4600 0.4833 0.0433 0.0833
3 0.7833 0.6350 0.1167 0.0933
6 0.3583 0.4933 0.1667 0.1700
The following is my attempt to solve the problem but the whole content just disappears:
path = 'file.txt'
with open(path, "r+") as f:
lines = f.readlines()
lines = str(int(lines[0].split()[0]) - 1)
with open(path, 'w') as file:
file.writelines(lines)
I really need help for this problem. I've been trying for hours. Thanks in advance