def insert(data):
import sqlite3
conn = sqlite3.connect("keywords.db")
conn.text_factory = str
c = conn.cursor()
c.execute("INSERT into PROJECT values (?)", (data,))
for row in c.execute("SELECT ROWID,* FROM PROJECT ORDER BY ROWID DESC LIMIT 1"):
print ("\nPOST VERIFIED:\n",row[0],row[1])
conn.commit()
conn.close()
return
ALL是包含搜索词的笔记本、行号和行的列表:Example:ALL=[“术语口罩存在于./arrays-for-seamless-cloning-checkpoint.ipynb中。\nLineNumber:‘,426,’”#在鼻子周围创建粗略的口罩“,\n‘)”,“术语口罩存在于./CLONING-CHECKPOINTT.ipynb.\nLineNumber:’,426,‘”#在眼睛周围创建粗略的口罩“,\n’)”]
for line in ALL:
print(line)
data = line
insert(data)
我需要将搜索结果插入到一个sqlite3数据库中
data = '''('The term mask exists in ./save-image-and-array-for-seamless-cloning-checkpoint.ipynb .\nLineNumber:', 426, ' "# Create a rough mask around the nose",\n')'''
---------------------------------------------------------------------------
InterfaceError Traceback (most recent call last)
Input In [35], in <cell line: 31>()
31 for line in ALL:
32 print(line)
---> 33 insert(line,)
Input In [35], in insert(data)
4 conn.text_factory = str
5 c = conn.cursor()
----> 6 c.execute("INSERT into PROJECT values (?)", (data,))
7 for row in c.execute("SELECT ROWID,* FROM PROJECT ORDER BY ROWID DESC LIMIT 1"):
8 print ("\nPOST VERIFIED:\n",row[0],row[1])
InterfaceError: Error binding parameter 0 - probably unsupported type.
我想搜索Jupyter笔记本中的术语,并在和数据库中输入结果。我有一本有数百本笔记本的笔记本,上面有很多片段。这将是一个简单的搜索过程。
1条答案
按热度按时间xzabzqsa1#
我把它修好了。我只需将数据称为字符串并删除\n:dataout=str(Data).place(“\n”,‘’)INSERT(DataOut)
这里有一个完整的要点:https://gist.github.com/JupyterJones/f23c5385ee85dbe85257b57b3fea4cd5,它在目录中的所有笔记本中搜索术语。然后将结果输入到SQLITE3数据库中