Python 使用pyodbc作为字典列表从SQL检索数据

Python 使用pyodbc作为字典列表从SQL检索数据,python,pyodbc,Python,Pyodbc,我已经阅读了问题及其答案。我能够使用pyodbc检索数据库数据: for row in cursor.fetchall(): print( row ) 然而,我只得到数据行,在每一行中 A, B, C D, E, F 我希望它像一本字典,每一列的标题也被指出,例如 studentName:A, studentAge:B, studentGrade: C studentName:D, studentAge:E, studentGrade: F 诸如此类,我怎样才能得到字典的列表 您可

我已经阅读了问题及其答案。我能够使用pyodbc检索数据库数据:

for row in cursor.fetchall():
    print( row )
然而,我只得到数据行,在每一行中

A, B, C
D, E, F
我希望它像一本字典,每一列的标题也被指出,例如

studentName:A, studentAge:B, studentGrade: C
studentName:D, studentAge:E, studentGrade: F

诸如此类,我怎样才能得到字典的列表

您可以尝试以下方法以获得预期结果:

for row in cursor.fetchall():
  print(row.studentName, row.studentAge, row.studentGrade)
希望有帮助。

有一个解决方案。可能重复的