I have read the question "Retrieving Data from SQL Using pyodbc" and its answers. I am able to retrieve DB data using pyodbc:
for row in cursor.fetchall():
print( row )
However I get only rows of data, in each row which looks like
A, B, C
D, E, F
I would like it like a dictionary where the title of each column is also indicated for example
studentName:A, studentAge:B, studentGrade: C
studentName:D, studentAge:E, studentGrade: F
and so on, how can I get a list of dictionaries?
You could try something like the following to get the expected results:
for row in cursor.fetchall():
print(row.studentName, row.studentAge, row.studentGrade)
Hope it helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.