简体   繁体   中英

Running Python Script on Mac/Windows

I have a python script that I wrote to analyze license plate data with the input being a CSV file and I wrote it on a Mac running Python 2.7.2 but when I try to run it on my work computer which is running Windows 8 I get an error. It gives me an error when it reaches the following line:

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

and it says:

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

How can it work on my Mac but not on my Windows computer? Both have Python version 2.7 installed

EDIT: when accessing elements in 'matches' they are of the format:

HH:MM:SS

EDIT: here is the full code

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])

and the CSV files that contain the initial data have lines of the following format:

HH:MM:SS,PLATE#

Problem solved. When the excel file I exported to CSV was created, there were headings across the top that needed to be removed

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM