I have 500 *.txt files which are of the form given below
1 0.211648 0.496528 0.230114 0.159722
11 0.549716 0.232639 0.082386 0.145833
5 0.687500 0.539931 0.130682 0.128472
1 0.534091 0.809028 0.221591 0.194444
2 0.127841 0.637153 0.119318 0.128472
2 0.579545 0.482639 0.090909 0.069444
1 0.657670 0.269097 0.105114 0.121528
2 0.737216 0.348958 0.025568 0.086806
2 0.484375 0.302083 0.031250 0.069444
I need to replace '11' 1st number in the row with '10' I have written following program for it but it doesn't work. can you please help.
import numpy as np
import glob
import os
os.chdir(r'../images')
myFiles = glob.glob('image*.txt')
import numpy as np
for i1 in myFiles:
# print(i1)
with open(i1, 'r') as f:
# read a list of lines into data
lines = f.readlines()
r_id = np.arange(len(lines))
for i in r_id:
idx = list(map(float, lines[i].split(' ')))
idx[0]=int(idx[0])
if(idx[0]==11):
idx[0]=10
with open(i1, 'w') as f:
f.writelines(lines)
f.close()
myFiles = glob.glob('image\*.txt')?