f = open('./val.txt')
lines = f.readlines() #整行读取
f.close()
for line in lines:
    rs = line.rstrip('\n') #去除原来每行后面的换行符,但有可能是\r或\r\n
    newname=rs.replace(rs,'/JPEGImages/'+rs+'.jpg'+' '+'/SegmentationClassAug/'+rs+'.png')
    newfile=open('.val1.txt','a')
    newfile.write(newname+'\n')
    newfile.close()
原文件                                       改后
 python 对txt中每行内容进行批量替换python 对txt中每行内容进行批量替换

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-31
  • 2021-08-09
  • 2021-10-16
  • 2022-01-31
  • 2021-11-28
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-28
  • 2021-09-15
  • 2022-12-23
  • 2021-07-05
  • 2022-02-03
  • 2022-12-23
相关资源
相似解决方案