I've been banging my head against a wall with the following error:
time
Traceback (most recent call last):
File "csvtest.py", line 37, in <module>
date = time.strptime(datestring, "%Y-%m-%d %H:%M:%S")
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_strptime.py", line 454, in _strptime_time
return _strptime(data_string, format)[0]
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_strptime.py", line 325, in _strptime
(data_string, format))
ValueError: time data 'time' does not match format '%Y-%m-%d %H:%M:%S'
The input is a row from a file with the format -- the year is purposefully junk data:
3354-03-16 15:30:00
3354-03-16 16:00:00
3354-03-16 16:30:00
3354-03-16 16:30:00
The code I'm using is below:
import sys
import csv
from datetime import datetime
import time
filename = open('data.csv', 'rb')
spam = csv.reader(filename, delimiter=',')
for row in spam:
datestring = row[4]
print datestring
date = time.strptime(datestring, "%Y-%m-%d %H:%M:%S")
filename.close()
time.strptime('3354-03-16 16:30:00', "%Y-%m-%d %H:%M:%S")returnstime.struct_time(tm_year=3354, tm_mon=3, tm_mday=16, tm_hour=16, tm_min=30, tm_sec=0, tm_wday=5, tm_yday=75, tm_isdst=-1)are you suredatestringcontains the data above?