Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/79.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
使用Cursor.executemany和Python列表插入_Python_Sql_Sqlite - Fatal编程技术网

使用Cursor.executemany和Python列表插入

使用Cursor.executemany和Python列表插入,python,sql,sqlite,Python,Sql,Sqlite,有人能给我解释一下这个代码有什么问题吗?我得到“参数类型不受支持”错误。无法将列表馈送到cursor.executemany中吗?列的类型为float not null random_numbers = [ 1, 2, 3, ] cursor.executemany('INSERT INTO Table (Column) VALUES (?)', random_numbers) cursor.executemany的值必须是元组序列: cursor.executema

有人能给我解释一下这个代码有什么问题吗?我得到“参数类型不受支持”错误。无法将列表馈送到cursor.executemany中吗?列的类型为float not null

random_numbers = [
    1,
    2,
    3,
]

cursor.executemany('INSERT INTO Table (Column) VALUES (?)', random_numbers)

cursor.executemany
的值必须是元组序列:

cursor.executemany('插入表(列)值(?),
[(n,)表示随机数中的n])

这是
游标的逻辑扩展。执行
时需要一个
元组
作为value参数。

谢谢,我想我明白了,但当我运行此命令时仍然会出现一个错误-“int object is not iterable”我的错,
元组(n)
仅在
n
是iterable时才有效。新版本应该可以用。啊,太棒了,谢谢。我检查了-你在第一个n后面的逗号是必需的-我确实读了一些关于为什么的东西,但我不太明白,所以我会再看一遍。非常感谢。后面的逗号是创建元组的工具。
导入随机数。clear()random\u numbers=[]对于范围(1000)内的i:random\u numbers.append((random.randint(10,25)))cursor.executemany('INSERT-INTO-Pressure VALUES(?),random\u numbers)
我很高兴地说这也有效!