Create data from csv¶
Import the sqlite and csv modules
1import csv 2import sqlite3
Point to the Library Database
4conn = sqlite3.connect("library.db") 5cursor = conn.cursor()
Read the csv file and insert the records into the database:
8with open("books.csv", encoding="utf-8") as f: 9 reader = csv.reader(f, delimiter=",") 10 cursor.executemany("INSERT INTO books VALUES (?,?,?,?,?)", reader)
Save data to database:
14conn.commit()