在Mac / Windows上运行Python脚本

时间:2013-07-08 05:44:06

标签: python python-2.7

我有一个python脚本,我写的是分析车牌数据,输入是一个CSV文件,我是在运行Python 2.7.2的Mac上写的,但是当我尝试在运行Windows的工作计算机上运行它时8我收到错误。当它到达以下行时,它会给我一个错误:

t1 = datetime.strptime(matches[z][1],'%H:%M:%S')

它说:

ValueError: time data 'TIME' does not match format '%H%M%S'

它如何在我的Mac上运行,而不是在我的Windows计算机上运行?两者都安装了Python 2.7版

编辑:访问“匹配”中的元素时,格式为:

HH:MM:SS

编辑:这是完整的代码

import csv
import difflib
from datetime import datetime

f = open('06 PM TUES.csv')
reader = csv.reader(f,delimiter=',')
data = []
for row in reader:
    data.append(row)

g = open('07 PM TUES.csv')
reader2 = csv.reader(g,delimiter=',')
data2 = []
for row in reader2:
    data2.append(row)

# Find Matches
matches = []
cut_through = []
for x in range(len(data)):
    for y in range(len(data2)):
        similarity = [difflib.SequenceMatcher(None,data[x][1],data2[y][1]).ratio()]
        if (similarity[0] > .75):
            if(data[x][1]!=''):
                matches.append(similarity+data[x]+data2[y])

# Calculate Time Difference
for z in range(len(matches)):
    t1 = datetime.strptime(matches[z][1],'%H:%M:%S')
    t2 = datetime.strptime(matches[z][5],'%H:%M:%S')
    if (abs(t1-t2).seconds < 91):
        cut_through.append([matches[z][0],matches[z][1],matches[z][2],matches[z][5],matches[z][6]])

# Print Results to CSV
with open('results.csv','wb') as test_file:
    file_writer = csv.writer(test_file)
    for i in range(len(cut_through)):
        file_writer.writerow(cut_through[i])

并且包含初始数据的CSV文件包含以下格式的行:

HH:MM:SS,PLATE#

1 个答案:

答案 0 :(得分:0)

问题解决了。当我创建导出到CSV的excel文件时,顶部有需要删除的标题