If you like the assurance that Python's with
statement provides, but can't figure out how to properly apply it to individual cursor objects, here's how to do that:
import sqlite3
from contextlib import closing
con = sqlite3.connect('example.db')
with con, closing(con.cursor()) as cur:
cur.execute(…)