I used row_factory in sqllite so that my rows can be returned in a dictionary format with column names. I used:
conn = sqlite3.connect('gutendex.db')
conn.row_factory = dict_factory
def dict_factory(cursor, row):
d = {}
for idx, col in enumerate(cursor.description):
d[col[0]] = row[idx]
return d
I want to use similar thing in mysql db as well but I couldnt find an alternative for it
Since this question does not has any answer and I solved the problem using the comment by Barmar I am pasting that as accepted solution.
The dictionary=True parameter to connection.cursor() tells it to return rows as dictionaries
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With