• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
MKT-porter
博客园    首页    新随笔    联系   管理    订阅  订阅
python读取文件列表修改txt内容

 

 

 

 

import os

filePath = 'img'
path2 = r'/config/FHY_gps.txt'
path3 = r'/config/FHY_gps_new.txt'
name = os.listdir(filePath)
name.sort(key=lambda x:float(x[:-4]))

file=open(path2)    
file2 = open(path3,'w+')
i=0
for line in file.readlines():
	curline=line.split(" ")
	rel_name = name[i].split('.')
	reline = rel_name[0] +"." +  rel_name[1] + " " + curline[1] + " " + curline[2] + " " + curline[3]
	print(rel_name[0],curline[1])
	print(reline+"\n")
	file2.write(reline)
	i=i+1
#file2 = open(path2,'w+')
#for x in name:
#    #rel_name = x.split('.')
#    line = x[:-4] + " " + "rgb/" + x + "\n"
#    file2.write(line)

  

posted on 2022-11-17 11:48  MKT-porter  阅读(144)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3