Py学习  »  Python

python数据库结果不能用于if语句

Steve8428 • 5 年前 • 1476 次点击  

我的数据从数据库中打印出来时是这样的。

[(0,), (0,), (0,), (0,), (0,), (0,)]

下面是我的python结果脚本

def readDbHeating():

   cursor = mariadb_connection.cursor()
   result = []
   try:
       cursor.execute("SELECT control FROM house_DB")
       for reading in cursor.fetchall():
           result.append(reading)
   except () as e:
       print(e)
   return (result)

while 1:
   result = readDbHeating()
   print result

   waterState = result[0]
   denState = result[3]
   niamhState = result[4]
   downWCstate = result[5]

   if(waterState == 0):
      print("here")
      flag = 0
      print("Water state = %s ") % waterState

我尝试将0设为“0”,并尝试将waterState的传入结果转换为整数,但得到的错误是这是一个元组

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/55864
 
1476 次点击  
文章 [ 2 ]  |  最新文章 5 年前