python生成TXT文件及转换为CSV文件源码

import datetime
with open(“D:/Luster/4.文档/CCDPoint.txt”,“w”) as f:
f.write(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
f.write("\r \n")
def CCD1Point(x,y,z,r,step):
CCD1=[[x,y,z,r],[x+step,y-step,z,r],[x-step,y+step,z,r],[x-step,y-step,z,r],[x+step,y+step,z,r],[x,y,z,r],[x,y,z,r+step],[x,y,z,r-step]]
return CCD1
def CCD2Point(x,y,z,r,step):
CCD2=[[x,y,z,r],[x-step,y+step,z,r],[x+step,y-step,z,r],[x+step,y+step,z,r],[x-step,y-step,z,r],[x,y,z,r],[x,y,z,r-step],[x,y,z,r+step]]
return CCD2
def writer(strCCD,listPoint):
c=0
index=0
with open(“D:/Luster/4.文档/CCDPoint.txt”,“a”) as file:
file.write("<"+strCCD+“CalibrationPoint”+">")
file.write("\r \n")
for i in listPoint:
file.write("<P"+str(index)+">")
for iteam in i:
file.write(str(iteam))
if c!=3:
file.write(",")
c+=1
else:c=0
file.write("\r \n")
index+=1
CCD1Step= (GvTool.GetToolData(“标准标定轴位置获取工具_550.X轴运动步长”) )
CCD2Step= (GvTool.GetToolData(“标准标定轴位置获取工具_590.X轴运动步长”))
str1=GetCommMes()
str2=GetCommMes()
writer(“CCD1”,CCD1Point(str1[0],str1[1],str1[2],str1[3],str1[4]))
writer(“CCD2”,CCD2Point(str2[0],str2[1],str2[2],str2[3],str2[4]))
with open(“D:/Luster/4.文档/CCDPoint.txt”,“a”) as f:
f.write("")
def newlist():
global strList
with open(“D:/Luster/4.文档/CCDPoint.txt”,“r”) as f:
listtxt=f.readlines()
a=len(listtxt)
newlisttxt=listtxt[2:a-1]
a1=len(newlisttxt)
strList=[]
for i in range(a1):
a2=list(newlisttxt[i])
if “>“in a2:
if a2.index(”>”)==len(a2):
pass
else:
a2.insert(a2.index(">")+1,",")
strList.append(a2)
else:pass
return strList
print(newlist())
def WriteCSV(newlist):
global strtxt
strtxt=""
for i in newlist:
for j in i:
strtxt += j
with open(“D:/Luster/4.文档/CCDPoint.csv”,“w”) as f:
f.write(strtxt)
WriteCSV(newlist())

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值