从mysqldb查询中获取原始十进制值 [英] get raw decimal value from mysqldb query

查看:107
本文介绍了从mysqldb查询中获取原始十进制值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MySQLdb包在python中执行mysql查询.代码看起来像这样:

I am executing a mysql query in python using the MySQLdb package. The code looks something like this:

c=db.cursor()
c.execute("""select * from table""")
output = []
for row in c:
    output.append(row[4])

其中row[4]包含一个要存储在output列表中的十进制值.

where row[4] contains a decimal value that I want to store in the output list.

问题是我得到的每个值都看起来像这样:Decimal('XX.XX')output列表中我想要的全部是XX.XX.在脚本末尾,我的output列表如下所示:

The problem is every value that I am getting looks like this: Decimal('XX.XX') where all I want in the output list is XX.XX. At the end of the script, my output list looks like this:

[Decimal('10.02'), Decimal('20.24'), ...]

但是我需要它仅包含数字,如下所示:

But I need it to just contain the numbers, like this:

[10.02, 20.24, ...]

我该怎么做?

谢谢!

推荐答案

c=db.cursor()
c.execute("""select * from table""")
output = []
for row in c:
    output.append(float(row[4]))

这篇关于从mysqldb查询中获取原始十进制值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆