pymysql只需选择值并保存到变量中

时间:2017-10-09 19:05:31

标签: python mysql select pymysql

cursor.execute("SELECT price FROM tabel WHERE id = 1600")
print cursor.fetchone()

给我输出

{u'price': u'4345.6'}

如何只选择值4345.6并将其保存在变量中以进行数学运算?

1 个答案:

答案 0 :(得分:1)

您可以通过以下代码安静轻松解决此问题。

data = cursor.fetchone() #get the data in data variable
value = float(data['price']) # load the data into value with conversion of its type