python写入csv文件中添加行,向CSV文件中添加一行,而不更改其格式(Python)

该博客讨论了一个Python脚本,该脚本打开日志文件,将特定信息写入新的CSV文件,然后比较日志文件中每个操作之间的时间差。问题在于如何在首次写入过程后,在不更改原始格式的情况下,将时间差添加到新CSV文件中。解决方案建议使用`csv.writer`,将时间差追加到每一行,并保持原有的CSV文件格式。
摘要由CSDN通过智能技术生成

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)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值