尝试使用" .strptime"在字典中拆分时间戳值。

时间:2016-05-07 14:03:25

标签: python dictionary python-3.4 strptime

尝试使用" .strptime"

在字典中拆分时间戳值

所以我有一组从.CSV文件导入到字典中的值。它们的格式为hh:mm:ss,但不是使用' .strptime'的正确数据类型。功能。 最终的结果是将字典中的每个时间戳转换为秒,但是我似乎无法获得' .strptime'因为值是错误的数据类型而工作。 是" .strptime"功能甚至是正确的使用?

到目前为止的代码:

from datetime import time
InTime=open("CameraIn.csv", 'rt')
OutTime=open("CameraOut.csv",'rt')

SpeedLimit = int(input("what is the speed limit? "))
#SpeedLimit = SpeedLimit*2.23694

line = InTime.readline()

InTimeByReg={}
OutTimeByReg={}

#def Speeding_Test(key):
#MetresInSeconds = int(OutTimeByReg(key)) - int(InTimeByReg(key))
#if MetresInSeconds > 26:
#    SpeedingCars = open("SpeedingCars.txt", "a")
#    SpeedingCars.write(str(key))


for line in InTime:
  (reg,time)= line.split(",")
  InTimeByReg[reg]=time.strip()

for line in OutTime:
  (reg,time)= line.split(",")
  OutTimeByReg[reg]=time.strip()

#for key in InTimeByReg:
#  Speeding_Test(key)

我导入的文件如下:

(CamerIn.csv): BD51 SMR,00:01:24 AV51 CDR,02:24:02 FP05 KLR,05:48:17 AH09 DPU,10:12:56 KL03 ZRC,16:43:59

(CameraOut.csv): BD51 SMR,00:02:00 AV51 CDR,02:24:42 FP05 KLR,05:48:58 AH09 DPU,10:13:20 KL03 ZRC,16:44:14

So far, here is the output from the code:

0 个答案:

没有答案