这是我的代码
#!usr/bin/python
from __future__ import print_function
import sqlite3
import os, sys, subprocess
import numpy as np
from Bio import Entrez
from Bio import Medline
Entrez.email = "shayezkarimcide@gmail.com"
handle = Entrez.esearch(db="pmc",
term = "Antimicrobial resistance",
rettype = "medline",retmode = "txt",
retmax= '10',sort = "pub date")
result = Entrez.read(handle)
handle.close()
Id = result ['IdList']
print (list(Id), "\n")
rint ("The length of PubId is :",len(Id))
conn = sqlite3.connect('/home/cbbi-l2-16/Desktop/karim')
c = conn.cursor()
print ("Opened database successfully")
c.executemany("INSERT INTO Entrez (PuId) VALUES (?)", Id)
for row in c :
print (row)
conn.commit()
print ("Records Save Successfully")
conn.close()?
给出错误
文件“ sqlpython.py”,第42行,在 c.executemany(“ INSERT INTO Entrez(PuId)VALUES(?)”,ID) sqlite3.ProgrammingError:提供的绑定数量不正确。当前语句使用1,并且提供了7。
答案 0 :(得分:0)
只需将?
中的参数添加为Id
。
根据sqlite3文档:
放入?作为要使用值的占位符,然后提供值的元组作为游标的execute()方法的第二个参数。
根据文档,在executemany
中也应如此,请看以下来自文档的示例:
更大的示例一次插入许多记录
购买= [('2006-03-28','购买','IBM',1000,45.00),
('2006-04-05','购买','MSFT',1000,72.00),
('2006-04-06','卖','IBM',500,53.00), ]
c.executemany('INSERT INTO stocks VALUES(?,?,?,?,?)',购买)