1.需求1
分析文本里面的数据,文本文件太大了,无法用optepad++打开
# coding=utf-8
import time
start=time.time()
filename = 'a.datconv.txt' # txt文件和当前脚本在同一目录下,所以不用写具体路径
data = []
with open(filename, 'r') as file_to_read:
while True:
line = file_to_read.readline() # 整行读取数据
if not line:
print('read end!!!')
break
#print(line)
p_tmp= [float(i) for i in line.split()] # 将整行数据分割处理
#列表生成,转化为浮点数
data.append(p_tmp[4])
#print(data)
f1 = open("write.txt", 'w')
for i in range(len(data)):#遍历,从头到尾
if data[i]>11 or data[i]<8:
f1.write(str(i) + ":" + str(data[i]) + "\n")#写入文件
f1.close()
end=time.time()
print(end-start)
2.需求2
提取时间戳,另存为csv文件,用excel打开,做差值(=A2-A1),然后插入图表,分析数据
# coding=utf-8
import time
start=time.time()
filename = 'ReceivedTofile-COM17-2021_7_20_19-20-54.DATconv.txt' # txt文件和当前脚本在同一目录下,所以不用写具体路径
data = []
with open(filename, 'r') as file_to_read:
while True:
line = file_to_read.readline() # 整行读取数据
if not line:
print('read end!!!')
break
#print(line)
p_tmp= [float(i) for i in line.split()] # 将整行数据分割处理
#列表生成,转化为浮点数
data.append(p_tmp[0])
print(data)
print(len(data))
f1 = open("write.csv", 'w')
for i in range(len(data)):
f1.write( str(data[i]) + "\n")
f1.close()
end=time.time()
print(end-start)