数据未上载到mysql workbench
我查了mysql工作台
import xlrd
import pymysql
book = xlrd.open_workbook("c:/Temp/exportimport201006.xls")
sheet = book.sheet_by_name("201006")
database = pymysql.connect(host = 'xxx', user = 'xxx', password = 'xxx', db = 'xxx')
cursor = database.cursor()
query = """INSERT INTO exportimport (year, hscode, expwgt, expdlr, impwgt, impdlr, balpayments) VALUES (%s, %s, %s, %s, %s, %s, %s)"""
for r in range(2, sheet.nrows):
year = sheet.cell(r,0).value
hscode = sheet.cell(r,1).value
expwgt = sheet.cell(r,2).value
expdlr = sheet.cell(r,3).value
impwgt = sheet.cell(r,4).value
impdlr = sheet.cell(r,5).value
balpayments = sheet.cell(r,6).value
values = (year,hscode,expwgt,expdlr,impwgt,impdlr,balpayments)
cursor.execute(query, values)
database.close()
虽然数据量不大,但还没有完成
哪一部分错了
我是Python初学者
似乎缺少了
cursor.execute
之后的提交操作编码如下:
相关问题 更多 >
编程相关推荐