PageRenderTime 22ms CodeModel.GetById 18ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/Doc/includes/sqlite3/row_factory.py

http://unladen-swallow.googlecode.com/
Python | 13 lines | 11 code | 2 blank | 0 comment | 2 complexity | 53a4712cc8d445085804bdcfafe17b01 MD5 | raw file
 1import sqlite3
 2
 3def dict_factory(cursor, row):
 4    d = {}
 5    for idx, col in enumerate(cursor.description):
 6        d[col[0]] = row[idx]
 7    return d
 8
 9con = sqlite3.connect(":memory:")
10con.row_factory = dict_factory
11cur = con.cursor()
12cur.execute("select 1 as a")
13print cur.fetchone()["a"]