小编Lyn*_*ynn的帖子

如何将SQL查询结果转换为python字典

我有difficuty将我的结果从查询转换为python字典.每个字典应该代表一个学生,键是列名,值是查询中的相应值,到目前为止,这是我提出的:

def all_students():
    qu= 'select * from students'
    crs.execute(qu)
    for row in crs:
        student= {"StudentNum":row[0], "StudentLastName":row[2], "StudentFirst Name":row[3}
    return student
Run Code Online (Sandbox Code Playgroud)

但是当我打印它时,它返回正确的信息,一切都不正常,它只显示一条记录:

{'StudentLastName': Jane, StudentNum: 'Smith  ', StudentFirst Name: '1612'}
Run Code Online (Sandbox Code Playgroud)

python sql dictionary

7
推荐指数
3
解决办法
2万
查看次数

标签 统计

dictionary ×1

python ×1

sql ×1