Python mysql-修复错误“TypeError:“long”对象不可编辑”
错误消息:Python mysql-修复错误“TypeError:“long”对象不可编辑”,python,mysql,flask,raspberry-pi,mysql-python,Python,Mysql,Flask,Raspberry Pi,Mysql Python,错误消息: TypeError: 'long' object is not iterable 错误消息中指出的代码: TypeError: 'long' object is not iterable def maxRowsTable: 对于x.Execute中的行,从传感器中选择COUNTtemp:this maxNumberRows=行[0] 返回maxNumberRows 我的MySQLdb连接: conn = MySQLdb.connect( host="localhost",
TypeError: 'long' object is not iterable
错误消息中指出的代码:
TypeError: 'long' object is not iterable
def maxRowsTable:
对于x.Execute中的行,从传感器中选择COUNTtemp:this
maxNumberRows=行[0]
返回maxNumberRows
我的MySQLdb连接:
conn = MySQLdb.connect(
host="localhost",
user="user",
passwd="pass",
database="data"
)
x = conn.cursor()
提前谢谢 由于查询返回单个记录,因此无需迭代 因此:
由于查询返回单个记录,因此不需要迭代 因此:
cursor.execute返回一个自动获取的迭代器。它应该是fetchone。Python不使用camelCase。对不起,我是一个完全的初学者。什么是x.fetchOne它说是AttributeError谢谢你的修复@Barmar。我确实需要提高我的python技能……显然,我的第一条评论取决于实现。标准Python游标规范没有说明cursor.execute返回什么。有些接口返回一个迭代器,但MysqlDB显然没有。cursor.execute返回一个自动获取的迭代器。它应该是fetchone。Python不使用camelCase。对不起,我是一个完全的初学者。什么是x.fetchOne它说是AttributeError谢谢你的修复@Barmar。我确实需要提高我的python技能……显然,我的第一条评论取决于实现。标准Python游标规范没有说明cursor.execute返回什么。有些接口返回迭代器,但MysqlDB显然不返回迭代器。您的查询只返回一行。为什么需要在循环中读取它?查询只返回一行。为什么你需要循环阅读?