Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.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
将MySQL查询结果存储到python变量中_Python_Mysql - Fatal编程技术网

将MySQL查询结果存储到python变量中

将MySQL查询结果存储到python变量中,python,mysql,Python,Mysql,当我使用python编程语言和MySQL数据库执行以下代码时 cursor.execute("select max(propernoun_SRNO) from tblauto_tagged") starting_index = cursor.fetchone() ending_index = starting_index +len(s) 我发现以下错误: Traceback (most recent call last): File "<pyshell#0>", line 1,

当我使用python编程语言和MySQL数据库执行以下代码时

cursor.execute("select max(propernoun_SRNO) from tblauto_tagged")
starting_index = cursor.fetchone()
ending_index = starting_index +len(s)

我发现以下错误:

Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
batch(1,1)
File "C:\Users\vchauhan\Dropbox\Code\proper_noun_function_batch_file_mysql_sept_12.py", line 97, in batch
ending_index = starting_index +len(s)
TypeError: unsupported operand type(s) for +: 'pyodbc.Row' and 'int'
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
批次(1,1)
文件“C:\Users\vchauhan\Dropbox\Code\property\u noon\u function\u batch\u File\u mysql\u sept\u 12.py”,第97行,分批
结束索引=开始索引+长度
TypeError:不支持+:'pyodbc.Row'和'int'的操作数类型
问题 这里的问题是,您正在将
pyodbc.Row
实例(由
.fetchone()
返回)赋值给
起始索引
,这使得无法将其添加到整数中(因此出现“TypeError:不支持的操作数类型”错误)

解决方案 尝试替换此行:

starting_index = cursor.fetchone()
starting_index = cursor.fetchone()[0]
这一行:

starting_index = cursor.fetchone()
starting_index = cursor.fetchone()[0]
更多阅读
  • (特别是关于
    fetchone()
    的部分)