PYTHON AND SQLITE
This section contains an assortment of Python files that illustrate how to perform various operations in sqlite3, which are the counterpart to the examples that you learned how to perform from the sqlite3 prompt. Note that the Python code samples use the mytools.db database instead of the test.db database.
Connect to a sqlite3 Database
Listing 4.26 displays the contents of connect_db.py that shows you how to connect to a sqlite3 database in Python.
LISTING 4.26: connect_db.py
import sqlite3
con = sqlite3.connect("mytools.db")
cursor = con.cursor()
con.commit()
con.close()
Listing 4.26 is a “do nothing” Python code sample that simply connects to the mytools.db database.
Create a Table in a sqlite3 Database
Listing 4.27 displays the contents of connect_db.py that shows you how to connect to a sqlite3 database in Python.
LISTING 4.27: create_table.py
import sqlite3
con = sqlite3.connect("mytools.db")
cursor = con.cursor()
cursor...