Skip to content

Instantly share code, notes, and snippets.

@omarjcero
Created October 28, 2021 17:40
Show Gist options
  • Save omarjcero/1fad063d2497a62a822bbadf4fb9262f to your computer and use it in GitHub Desktop.
Save omarjcero/1fad063d2497a62a822bbadf4fb9262f to your computer and use it in GitHub Desktop.
Get a dictionary from query in python
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