Create a dictionary in Python receiving values from the database

1

After accessing the database and having the desired query in case:

...
c =  conn.cursor()
c.execute('SELECT 'tb1'.'Nome', 'tb1'.'Apelido' FROM tb1')

How do I create a python dictionary for my above command?

dict = {Nome:'Apelido'} ...
?
    
asked by anonymous 10.07.2015 / 20:19

1 answer

1

You can try using the cursor.fetchall (), explained here .

It returns a list of tuples with the result of your SELECT. From this, it's easy to turn it into a dictionary.

You can still pass a parameter (dictionary = True), which for me has not worked yet. See here

Good job!

    
10.07.2015 / 21:41