source:
trunk/essentials/dev-lang/python/Doc/lib/sqlite3/row_factory.py
| Last change on this file was 3225, checked in by , 19 years ago | |
|---|---|
| File size: 291 bytes | |
| Line | |
|---|---|
| 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"] |
Note:
See TracBrowser
for help on using the repository browser.
