Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.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/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 3.x 操作错误:无此类列:无_Python 3.x_Sqlite - Fatal编程技术网

Python 3.x 操作错误:无此类列:无

Python 3.x 操作错误:无此类列:无,python-3.x,sqlite,Python 3.x,Sqlite,当我尝试运行下面的代码时,我得到了错误消息:OperationalError:no这样的列:None。这个错误是因为SQLite行迭代器返回了一个“None”,当我执行str(行)时,null值为 我可以对字符串进行替换,然后替换,None,with,Null,但我想知道是否有更好的解决方案 for row in c.execute(sqlStr): tmp = str(row)[:-1] +', ' + str(rowCount) + ')' insertStr = 'Inse

当我尝试运行下面的代码时,我得到了错误消息:OperationalError:no这样的列:None。这个错误是因为SQLite行迭代器返回了一个“None”,当我执行str(行)时,null值为

我可以对字符串进行替换,然后替换,None,with,Null,但我想知道是否有更好的解决方案

for row in c.execute(sqlStr):
    tmp = str(row)[:-1] +', ' + str(rowCount) + ')'
    insertStr = 'Insert into  tblMain (userID, PlayedTimeStamp, TimeSinceFirstPlay,ArtistID, ArtistName, TrackID, TrackName,historyID) Values ' + tmp
    c.execute(insertStr)

您在每次循环迭代中都在构建和执行语句,但我想您想要的是先收集要插入的数据(在
tmp
),然后将其连接到语句。因此,您列出了8个要插入数据的列,但每个循环迭代只提供两个列。更重要的是,您的代码片段没有显示
rowCount
的来源,我猜它没有定义,因此在尝试将其转换为字符串时被替换为“None”


总而言之,代码相当难看,有点模糊;我建议清理它,并使用
print
语句来调试查询的实际内容。

不是答案,但我认为您忘记了
在值之后)