我使用了从日志文件中读取的以下格式,使用的格式化程序与DateTime格式匹配。不知道为什么它仍然会出错。-ValueError:时间数据“'2018-01-01 10:00:00'”与格式'%Y-%m-%d%H:%M:%S'不匹配
f = open("log.txt", 'w')
f.write("UID, SID, LogTime\n")
f.write("1, 1, '2018-01-01 10:00:00'\n")
f.write("1, 1, '2018-01-01 10:30:00'\n")
f.write("1, 1, '2018-01-01 11:30:00'\n")
f.close()
x = open("log.txt", 'r')
print (x.read())
x.close()
import numpy as np
from datetime import datetime
a = open("log.txt", 'r+')
temp = None
header = a.readline()
for line in a:
line = line.strip()
columns = line.split(',')
print (columns)
UID = columns[0]
SID = columns[1]
print (columns[2])
LogTime = datetime.strptime(columns[2],"%Y-%m-%d %H:%M:%S")
a.write(','+LogTime-temp)
temp = LogTime
函数式编程
千万里不及你
相关分类