rowdicts[ {'pay' 'job''mus''name''sue'and finallya list comprehension will do the job of collecting the dictionaries into list--not only is this less to typebut it probably runs quicker than the original versioncurs execute('select from people'colnames [desc[ for desc in curs descriptionrowdicts [dict(zip(colnamesrow)for row in curs fetchall()rowdicts[ {'pay' 'job''mus''name''sue'one of the things we lose when moving to dictionaries is record field order--if you look back at the raw result of fetchallyou'll notice that record fields are in the namejoband pay order in which they were stored our dictionary' fields come back in the pseudorandom order of python mappings as long as we fetch fields by keythis is irrelevant to our script tables still maintain their orderand dictionary construction works fine because the description result tuple is in the same order as the fields in row tuples returned by queries we'll leave the task of translating record tuples into class instances as suggested exerciseexcept for two hintspython' standard library collections module implements more exotic data typessuch as named tuples and ordered dictionariesand we can access fields as attributes rather than as keysby simply creating an empty class instance and assigning to attributes with the python setattr function classes would also provide natural place to code inheritable tools such as standard display methods in factthis is part of the utility that the upcoming orms can provide for us automating with scripts and modules up to this pointwe've essentially used python as command-line sql client--our queries have been typed and run interactively all the kinds of code we've runthoughcan be used as the basis of database access in script files working interactively requires retyping things such as multiline loopswhich can become tedious with scriptswe can automate our work to demonstratelet' make the last section' prior example into utility module-example - is reusable module that knows how to translate the result of query from row tuples to row dictionaries example - pp \dbase\sql\makedicts py ""convert list of row tuples to list of row dicts with field name keys this is not command-line utilityhardcoded self-test if run ""def makedicts(cursorqueryparams=())cursor execute(queryparamscolnames [desc[ for desc in cursor descriptionsql database interfaces