我有一个csv文件。我想迭代行并生成sql字符串。我尝试了stackoverflow中的解决方案,但无法修复它。你知道吗
csv文件
rating,product_type,upc,title
Three,Books,a897fe39b1053632,A Light in the Attic
One,Books,6957f44c3847a760,Soumission
python文件以以下代码开头
path = r'C:\Users\HP\PycharmProjects\book_crawler\books\items.csv'
file = open(path, 'rt')
我尝试了不同版本的字符串格式。我得到的一些错误:
索引器:元组索引超出范围
for row in file:
print ('INSERT IGNORE INTO books_table(rating, product_type, upc, title) VALUES({},{},{},{})'.format(row))
类型错误:并非所有参数都在字符串格式化期间转换
for row in file:
print ('INSERT IGNORE INTO books_table(rating, product_type, upc, title) VALUES({0},{1},{2},{3})' % row)
类型错误:并非所有参数都在字符串格式化期间转换
for row in file:
print ('INSERT IGNORE INTO books_table(rating, product_type, upc, title) VALUES({0},{1},{2},{3})' % (row,))
类型错误:并非所有参数都在字符串格式化期间转换
for row in file:
print ('INSERT IGNORE INTO books_table(rating, product_type, upc, title) VALUES({0},{1},{2},{3})' % tuple(row))
我不完全确定您想做什么,但是要分析csv文件并用csv值生成
mysql
查询,您可以使用:输出:
相关问题 更多 >
编程相关推荐