Python 仅获取 dict 值,没有来自 Mysql 的键

Python Get dict value only, without key from Mysql

在Python3中,我通过字典从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

sql = "SELECT count(point) from matches where month = '12'"
self.cursor.execute(sql)
return self.cursor.fetchone()

函数return字典:

{'count(point)': 15}

我已经尝试使用

staffCrt['B'].values()

但是 return dict_values([15])

如何只获取值“15”?

从字典中获取某个值:

基本上,d[key] = value

dict_values :

如果你在字典 d 上调用 d.values(),那将 return 一个 dict_values 对象,如果你想的话,你应该在 list 中转换它访问其数据。 list(d.values())

你的问题:

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

那么,如果output是函数的return:

output['count(point)'] 

将return15

根据您的编辑:

其实output = staffCrt['B']所以,

staffCrt['B']['count(point)'] = 15