Skip to content

Instantly share code, notes, and snippets.

@lucnap
Created September 27, 2020 07:48

Revisions

  1. lucnap created this gist Sep 27, 2020.
    16 changes: 16 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@

    def generatefieldmap(cursor):
    """ Given a DB API 2.0 cursor object that has been executed, returns
    a dictionary that maps each field name to a column index; 0 and up. """
    results = {}
    column = 0
    for d in cursor.description:
    results[d[0]] = column
    column = column + 1

    return results


    # usage
    fmap = generatefieldmap(cur);
    print(row[fmap['nome']])