错误消息:
TypeError: 'long' object is not iterable
错误消息中指出的代码:
def maxRowsTable():
for row in x.execute("SELECT COUNT(temp) from sensors"): #this
maxNumberRows=row[0]
return maxNumberRows
我的MySQLdb连接:
conn = MySQLdb.connect(
host="localhost",
user="user",
passwd="pass",
database="data"
)
x = conn.cursor()
提前谢谢!
答案 0 :(得分:0)
由于查询返回单个记录,因此无需进行迭代。
所以:
x.execute("SELECT COUNT(temp) from sensors")
row = x.fetchone()
maxNumberRows = row[0]