簡體   English   中英

在Mac / Windows上運行Python腳本

[英]Running Python Script on Mac/Windows

我寫了一個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#

問題解決了。 創建我導出為CSV的Excel文件后,頂部的標題需要刪除

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM