Python只获取dict值,不从Mysq获取key

2024-10-02 10:18:17 发布

您现在位置:Python中文网/ 问答频道 /正文

在Python3中,我通过dict从Mysql获取值(使用pymysql.cursors.SSDictCursor

但是,我将get point and display函数写入html(Flask),它显示dict key&dict

这是我的密码

staffCrt['B'] = repo.countstaff(month['bonus'], ">", line[0])
staffCrt['S'] = repo.countstaff(month['bonus'], "<", line[0])   
staffList.append(staffCrt)

countstaff()中的SQL

^{2}$

函数返回dict:

{'count(point)': 15}

我试着用

staffCrt['B'].values()

但它回来了 dict_值([15])

我怎样才能只得到值“15”?在


Tags: 函数getlinemysqlrepodictpython3point
1条回答
网友
1楼 · 发布于 2024-10-02 10:18:17

从dict获取某个值:

基本上,d[key] = value

dict_值:

如果您对dict d调用d.values(),那么它将返回一个dict_values对象,如果您想访问它的数据,您应该在list中转换该对象。list(d.values())

您的问题:

The function return the dict: {'count(point)': 15}

那么,如果output是函数的返回:

output['count(point)'] 

将返回15

编辑:

实际上output = staffCrt['B']所以

^{pr2}$

相关问题 更多 >

    热门问题