首页 > 编程语言 >python读取文件列表修改txt内容

python读取文件列表修改txt内容

时间:2022-11-17 11:56:41浏览次数:37  
标签:file2 读取 curline python rel line txt name

 

 

 

 

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)

  

标签:file2,读取,curline,python,rel,line,txt,name
From: https://www.cnblogs.com/gooutlook/p/16898992.html

相关文章

  • python 子类调用父类中的init
    背景在定义完父类后,子类继承父类后,又想有自己的__init__方法方法在子类的__init__方法中调一下父类的___init__方法代码classTest1:def__init__(self):......
  • 工-python注解
    1、无参数和带参数defspamrun(fn):defsayspam(*args):print("spam,spam,spam")fn(*args)returnsayspam@spamrundefuseful(a,b):......
  • python中networkx学习(1)边和点
    importnetworkxasnxfrommatplotlibimportpyplotaspltG=nx.Graph(abb="pythondemo")#创建一个空图print(nx.Graph)#添加节点G.add_node("python")#生成一个以......
  • PYTHON_循环
    分模块积累,此模块为【循环】。1. 有四个数字1、2、3、4,能组成多少个互不相同且无重复的三位数,各是多少?'''初始化'''cnt=0'''循环判断获得无重复三位数'''foriinr......
  • Python selenium 插入图片
    方法一如果有上传图片按钮的,就比较简单了:browser.find_element_by_id("IdOfInputTypeFile").send_keys(os.getcwd()+"/image.png")browser.find_element_by_xpath("IdOfInpu......
  • python web自动化-文件上传三种方法
    文件上传三种方式:(一)查看元素标签,如果是input,则可以参照文本框输入的形式进行文件上传方法:和用户输入是一样的,使用send_keys步骤:1、找到定位元素,2,输入文件路径ele=driv......
  • python xls2csv
    importpandasaspdaex=pda.read_excel("k.xls")ex.to_csv("k.csv",encoding="gbk") importpandasaspdacs=pda.read_csv("k.csv",encoding="gbk")cs.to_exc......
  • Python中为啥 int('12', 16) 的结果是 18?
    大家好,我是皮皮。一、前言前几天在Python白银交流群【SamYao】问了一个Python基础的问题,提问截图如下:二、实现过程其实他自己发出来的解析已经比较清晰了,如下图所示:......
  • python flask学习之Mac开发flask项目中bash: flask: command not found错误解决
    最近在学习pythonflask时,当使用SQLAlchemy对mysql操作的功能要做flask_migrate迁移在执行flask的命令【flaskdbinit】时,控制台报bash:flask:commandnotfound错误......
  • Chromium内核浏览器(Edge、Chrome)读取串口数据
    chromium内核89版本以上的浏览才支持域名或IP访问时需要HTTPS,localhost没有限制什么是web串行APIWeb串口API为网站提供了一种阅读和写入带有JavaScript的串行设......