我的头撞到了墙上,错误如下:time
Traceback (most recent call last):
File "csvtest.py", line 37, in
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'
输入是一个文件中的一行,格式为“年份”故意是垃圾数据:
^{pr2}$
我使用的代码如下: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()