我正在尝试将csv文件插入mysql但我的datetime字段中有错误。我尝试了这个,但在这一行上发现了这个错误..... date,time = startdatetime.split(' /') ValueError:需要多于1个值才能解压缩mycsv文件行如下:
2880,HY13KZV,2014/07/07 09:34:28,2014/07/08 09:34:28,1280
2880,RK09UZB,2014/07/07 10:34:05,2014/07/07 16:34:05,640
for row in reader:
print row
try:
(machine_name,vrm,startdatetime,enddatetime,ticket_price) = [x.decode('utf-8-sig') for x in row]
except:
print "Error with row: " % row
tmp = startdatetime.split(" ")
tmp = enddatetime.split(" ")
vrm = vrm.replace(' ','')
vrm = vrm.upper()
ticket_price = int( SessionCost / 100)
date,time = startdatetime.split('/')
month,day,year = startdate.split('/')
entryDatetime = "%s-%s-%s %s" % (year,month,day,time)
date,time = enddatetime.split('/')
month,day,year = enddate.split('/')
expiryDatetime = "%s-%s-%s %s" % (year,month,day,time)
sql_local = """INSERT INTO customer_1.pay_and_display
(plate, machine_id, ticket_datetime, expiry_datetime, ticket_name, ticket_price)
VALUES ("%s", "%s", "%s", "%s", "%s", "%s") """ % (vrm, machine_name, entryDatetime, expiryDatetime, "Ringo", SessionCost)
print sql_local
cursor.execute(sql_local)
curl = pycurl.Curl()
body = Body()
答案 0 :(得分:1)
你的问题正在分裂" /"带出3个字段
year,month,day = startdatetime.split('/')
实际上还有一些错误。在其位置使用以下内容
date,time = startdatetime.split(' ')
year,month,day = date.split('/')
hour,min,second = time.split(':')