Skip to content

Commit

Permalink
Show how to do a dict row factory
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerbinns committed Jan 23, 2015
1 parent 19e58f4 commit 765abda
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion doc/tips.rst
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,14 @@ appropriate. The cursor only has two important methods -
If you want to change the rows returned then use a :ref:`row tracer
<rowtracer>`. For example you could call
:meth:`Cursor.getdescription` and return a dictionary instead of a
tuple.
tuple::

def row_factory(cursor, row):
return {k[0]: row[i] for i, k in enumerate(cursor.getdescription())}

# You can also set this on just a cursor
connection.setrowtrace(row_factory)


.. _busyhandling:

Expand Down

0 comments on commit 765abda

Please sign in to comment.