Created
October 28, 2021 17:40
-
-
Save omarjcero/1fad063d2497a62a822bbadf4fb9262f to your computer and use it in GitHub Desktop.
Get a dictionary from query in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cursor = connection.cursor() | |
cursor.execute(sql) | |
columns = [column[0] for column in cursor.description] | |
results = [] | |
for row in cursor.fetchall(): | |
results.append(dict(zip(columns, row))) | |
print(results) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment