我正在尝试使用Python(enthoughtcanopy编辑器)从csv文件构建一个sqlite数据库。 我想将文件夹中包含的所有csv文件导入到单独的表中,表名是根据csv文件名指定的。 到目前为止,我已经成功地将在线找到的代码块复制并粘贴到以下位置:
import csv
import sqlite3
# Create the database
connection = sqlite3.connect('C:/ROAST/3_ANALYSIS/03_SQL-PY/primo.db')
cursor = connection.cursor()
# Create the table
cursor.execute('DROP TABLE IF EXISTS A08')
cursor.execute('CREATE TABLE A08 (uno, due, tre) ')
connection.commit()
# Load the CSV file into CSV reader
csvfile = open('C:/ROAST/3_ANALYSIS/03_SQL-PY\A08_csv/A08_B1_T5.csv', 'rb')
creader = csv.reader(csvfile, delimiter=',', quotechar='|')
# Iterate through the CSV reader, inserting values into the database
for t in creader:
cursor.execute('INSERT INTO A08 VALUES (?,?,?)', t )
# Close the csv file, commit changes, and close the connection
csvfile.close()
connection.commit()
connection.close()'
下面是我如何解决你的问题。在
适当地替换最后的
^{pr2}$__main__
部分。也许你会想要:或者
相关问题 更多 >
编程相关推荐