+ -

Pages

Tuesday, June 11, 2013

using a sql statementto assign keys & values to a dict

If you run a sql statement, and want to iterate over the cursor to assign keys and values to a dictionary, do the following:


  1. >>> my_dict={}
  2. >>> for key, value in cur.execute('select badge, name from sched'):
  3.         my_dict[key]=value
5 Khalid's Python Journal: using a sql statementto assign keys & values to a dict If you run a sql statement, and want to iterate over the cursor to assign keys and values to a dictionary, do the following: >>...

No comments:

Post a Comment

>