Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1 | import sqlite3 |
2 | |||||
3 | def dict_factory(cursor, row): | ||||
4 | d = {} | ||||
5 | for idx, col in enumerate(cursor.description): | ||||
6 | d[col[0]] = row[idx] | ||||
7 | return d | ||||
8 | |||||
9 | con = sqlite3.connect(":memory:") | ||||
10 | con.row_factory = dict_factory | ||||
11 | cur = con.cursor() | ||||
12 | cur.execute("select 1 as a") | ||||
13 | print(cur.fetchone()["a"]) |