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())
python生成TXT文件及转换为CSV文件源码
最新推荐文章于 2024-06-07 10:29:43 发布