在Python3中,我根据dict从Mysql
中获取价值。 (使用pymysql.cursors.SSDictCursor
)
但是,我编写函数get point并显示到html
(烧瓶)中,它显示了dict键和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()
该函数返回字典:
{'count(point)': 15}
我尝试使用
staffCrt['B'].values()
但它返回 dict_values([15])
我怎样才能只获得值“ 15”?
答案 0 :(得分:3)
通过dict访问特定值:
基本上,d[key] = value
dict_values:
如果在字典d.values()
上调用d
,则将返回一个dict_values
对象,如果要访问其数据,应在list
中对其进行转换。 list(d.values())
您的问题:
该函数返回字典: {'count(point)':15}
然后,如果output
是函数的返回值:
output['count(point)']
将返回15
进行编辑:
实际上output = staffCrt['B']
是这样,
staffCrt['B']['count(point)'] = 15