本次的需求是从文本中,获取指定行的信息,获取时间戳,写入到csv,对比时序。完整的代码如下:
import csv
filename = "0828.log"
lines = []
with open(filename, 'r') as file:
lines = file.readlines()
filename_csv = "0828.csv"
with open(filename_csv, "a", newline='') as f:
writer = csv.writer(f)
writer.writerow(["times_1", "selt_time"])
for str in lines:
if '[PPS Dispatch] front_radar_timestamps =' in str:
num_str1 = ''
num_str2 = ''
str1, str2 = str.split(',')
for char in str1:
if char.isdigit():
num_str1 += char
for char in str2:
if char.isdigit():
num_str2 += char
row = [num_str1, num_str2]
writer.writerow(row)