如:把文件里每行的首名称都改为路径 

import os
path0 = r'C:\Users\admin\Desktop/cc.txt'
path1 = r'C:\Users\admin\Desktop/dd.txt'
path1 = open(path1, 'w')

for i, line in enumerate(open(path0).readlines()):
    strs = line.strip().split(" ")
    strs = list(filter(lambda x: bool(x), strs))
    name = strs[0].strip()
    print('name:', name)
    name_ = os.path.join(r'D:\mtcnndata1\img2', name)
    print('name_:', name_)
    path1.write('{0} {1} {2} {3} {4}\n'.format(name_, strs[1], strs[2], strs[3], strs[4]))

批量修改文件内的某部分内容 python

批量修改文件内的某部分内容 python

相关文章:

  • 2021-12-09
  • 2021-06-02
  • 2021-09-13
  • 2021-06-21
  • 2022-12-23
  • 2021-05-15
  • 2022-12-23
猜你喜欢
  • 2021-12-07
  • 2022-12-23
  • 2021-12-13
  • 2022-12-23
  • 2022-12-23
  • 2021-12-31
  • 2021-08-05
相关资源
相似解决方案