使用Cursor.executemany和Python列表插入
有人能给我解释一下这个代码有什么问题吗?我得到“参数类型不受支持”错误。无法将列表馈送到cursor.executemany中吗?列的类型为float not null使用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
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)
我很高兴地说这也有效!