假设需要将原索引“0,1,2,3”都修改为“0”:
import os
path = 'train'
total_txt = os.listdir(path)
deleteList = []
for file in total_txt:
fileName = path + '/' + file
file = open(fileName, 'r')
lines = file.readlines()
for index, line in enumerate(lines):
strT = lines[index]
if strT[0:1] == "0":
strT = "0 "+strT[2:]
lines[index] = strT
elif strT[0:1] == "1":
strT = "0 "+strT[2:]
lines[index] = strT
elif strT[0:1] == "2":
strT = "0 "+strT[2:]
lines[index] = strT
elif strT[0:1] == "3":
strT = "0 "+strT[2:]
lines[index] = strT
file.close()
strT = "".join(lines)
file = open('new/' + fileName, 'w')
file.write(strT)
file.close()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)