Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python mysql-修复错误“TypeError:“long”对象不可编辑”_Python_Mysql_Flask_Raspberry Pi_Mysql Python - Fatal编程技术网

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显然不返回迭代器。您的查询只返回一行。为什么需要在循环中读取它?查询只返回一行。为什么你需要循环阅读?