使用QUERY = SELECT score as SCORE FROM USER1.TABLE1 WHERE id = 101 ORDER BY score DESC
output = []
results = db.engine.execute(QUERY)
[output.append(dict(row)) for row in results]
在oracle上执行SQL
Decimal
输出:
[{'score':Decimal('0.9556')},.....]
得分数据类型-Number(16,14)
SELECT CAST(score as FLOAT) as SCORE FROM USER1.TABLE1 WHERE id = 101 ORDER BY score DESC
吗? 我尝试将得分转换为浮点数
Queue
我正在获得输出,
[{'score':0.9191699999999999},.....]
答案 0 :(得分:0)
通过添加代码块,使用Counter
类可能是一个不错的选择
from collections import Counter
str=output[0]
c = Counter()
for k,v in str.items():
c.update({k.upper(): '{0:f}'.format(v)})
print(c)
到原始代码的以下部分。这样,您得到的输出为
Counter({'SCORE': '0.9556'})