Popular recipes by Tom Jenkins http://code.activestate.com/recipes/users/98163/2001-03-21T11:05:52-08:00ActiveState Code RecipesGenerate field name to column number dictionary (Python)
2001-03-21T11:05:52-08:00Tom Jenkinshttp://code.activestate.com/recipes/users/98163/http://code.activestate.com/recipes/52293-generate-field-name-to-column-number-dictionary/
<p style="color: grey">
Python
recipe 52293
by <a href="/recipes/users/98163/">Tom Jenkins</a>
(<a href="/recipes/tags/database/">database</a>).
</p>
<p>When you get a set of rows from a cursor.fetch[one, many, all] call, it is sometimes helpful to be able to access a specific column in a row by the field name and not the column number. This function takes a DB API 2.0 cursor object and returns a dictionary with column numbers keyed to field names.</p>