Dev HelpersOpen library
← Back

Read SQLite result rows by name

Read SQLite result rows by name in Python.

Open this example in the interactive library

Source code

from contextlib import closing
import sqlite3
with closing(sqlite3.connect(':memory:')) as db:
    db.row_factory = sqlite3.Row
    print(dict(db.execute('SELECT ? AS title, ? AS score', ('Ada', 9)).fetchone()))

Sample output

{'title': 'Ada', 'score': 9}