mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
[1.9.x] Fixed #25455 -- Optimized dictfetchall() example.
Thanks aklim007 for the suggestion.
Backport of 361f60479d from master
This commit is contained in:
@@ -282,9 +282,9 @@ using something like this::
|
|||||||
|
|
||||||
def dictfetchall(cursor):
|
def dictfetchall(cursor):
|
||||||
"Return all rows from a cursor as a dict"
|
"Return all rows from a cursor as a dict"
|
||||||
desc = cursor.description
|
columns = [col[0] for col in cursor.description]
|
||||||
return [
|
return [
|
||||||
dict(zip([col[0] for col in desc], row))
|
dict(zip(columns, row))
|
||||||
for row in cursor.fetchall()
|
for row in cursor.fetchall()
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user