社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

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

Steve8428 • 5 年前 • 1343 次点击  

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

[(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
 
1343 次点击  
文章 [ 2 ]  |  最新文章 5 年前