Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.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 将元组转换为列表时出现非类型错误_Python_Sqlite - Fatal编程技术网

Python 将元组转换为列表时出现非类型错误

Python 将元组转换为列表时出现非类型错误,python,sqlite,Python,Sqlite,我正在尝试从sqlite数据库中选择一行。进行一些更改,然后将它们提交回sqlite数据库和mysql数据库 我尝试的方法是将SELECT查询检索到的tuple转换为列表,以进行更改 key = 27361 c.execute("SELECT * FROM employees WHERE key = ?", (key,)) employeeTuple = c.fetchone() employeeList = list(employeeTuple) 我得到一个错误: TypeError: 'N

我正在尝试从sqlite数据库中选择一行。进行一些更改,然后将它们提交回sqlite数据库和mysql数据库

我尝试的方法是将
SELECT
查询检索到的
tuple
转换为
列表
,以进行更改

key = 27361
c.execute("SELECT * FROM employees WHERE key = ?", (key,))
employeeTuple = c.fetchone()
employeeList = list(employeeTuple)
我得到一个错误:

TypeError: 'NoneType' object is not iterable
cursor.fetchone()
如果没有匹配的行,则返回
None
。您没有与
key=27361
匹配的行

在这种情况下,您可以使用
if employeeTuple
或使用
对短路进行测试,并将
None
分配给
employeeList

# if employeeTuple is None employeeList will not be set at all
if employeeTuple:
    employeeList = list(employeeTuple)

cursor.fetchone()
如果没有匹配的行,则返回
None
。您没有与
key=27361
匹配的行

在这种情况下,您可以使用
if employeeTuple
或使用
对短路进行测试,并将
None
分配给
employeeList

# if employeeTuple is None employeeList will not be set at all
if employeeTuple:
    employeeList = list(employeeTuple)

直接来自“获取查询结果集的下一行,返回单个序列,或在没有更多数据可用时无”直接来自“获取查询结果集的下一行,返回单个序列,或在没有更多数据可用时无”
# if employeeTuple is None employeeList will be set to the empty list
employeeList = list(employeeTuple or [])