sqlite通过python仅插入最后一个元素

时间:2018-10-11 19:06:20

标签: python sqlite

这是我在python中的代码,我想将所有结果插入sqlite3数据库中,但它仅在sqlite3中插入最后一个元素,“ r”的值是一个数字序列,“ resu”是r的结果,在文本中

#!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']

for r in Id:
    print (r)

print (list(Id), "\n")
print ("The length of PubId is :",len(Id))

handle2 = Entrez.efetch(db="pmc", 
                        id=Id, rettype="medline", 
                        retmode="text")

records = Medline.parse(handle2)

for result in records:
    resul = result['AB']
    res = (resul)

    print (res,'\n')
    print ()

handle2.close()

#######################    Sqlite3 Connect ##################
conn = sqlite3.connect('/home/karim/Desktop/karim')
c = conn.cursor()
print ("Opened database successfully")
example =[(r,res)]
c.executemany('INSERT INTO Entrez(PubId,Abstract)  VALUES 
(?,?)',example)
conn.commit()
print("Records Save Successfully")
conn.close()

解决方法

0 个答案:

没有答案