I'm working on a python script that opens a logfile, writes specific information to a new csv file and then compares the time difference between each action within the log file. The problem I'm having is that I need to figure a way to add the time difference to the new csv file after it was closed during the first writing process. This is what I have so far for that part.
final_file = open('FinalLogFile.csv', 'w')
temp_logfile = csv.reader(open('tempLogFile.csv', 'rb'), delimiter="\t")
fmt = '%Y-%m-%d %H:%M:%S.%f'
row_count = 0
#find the time between each action and write it to the new file
#transfer actions from temp file to final file
for row in temp_logfile:
time = (row[0] + " " + row[1])
timestamp = strptime(time, fmt)

该博客讨论了一个Python脚本,该脚本打开日志文件,将特定信息写入新的CSV文件,然后比较日志文件中每个操作之间的时间差。问题在于如何在首次写入过程后,在不更改原始格式的情况下,将时间差添加到新CSV文件中。解决方案建议使用`csv.writer`,将时间差追加到每一行,并保持原有的CSV文件格式。
最低0.47元/天 解锁文章
4万+

被折叠的 条评论
为什么被折叠?



