使用 python 在 Sqlite3 中创建某些条件时混淆创建打印输出
confuse create print out when create some condition in Sqlite3 with python
我创建了一个名称为 table 的测试数据库,其中有两列分别名为 Words 和 Sentences,我想在数据库 (sqlite3) 中搜索是否存在数据或单词or not,如果有那么系统会输出/打印 from table sentence 。我对这部分感到困惑。我试着编写这段代码,但它没有出现我想要的结果。
import sqlite3 as lite
import sys
connection = lite.connect('test.db')
with con:
cur = con.cursore()
cur execute("Select words From test")
inpt = "what the meaning of python ?"
for word in stn.split():
if word in words:
print Sentence
我把一个句子分成几个单词,然后在数据库中搜索,变量inpt中的单词是否在单词列中,如果有则系统将打印列句子。
我创建了一个这样的数据库:
words Sentences
---------- -------------------
Python Python is a program language
Django web framework for python
我想这就是您要找的。
import sqlite3 as lite
con = lite.connect('test.db')
with con:
cur = con.cursor()
for row in cur.execute("Select words, Sentences From test"):
inpt = "what the meaning of Python ?"
if row[0] in inpt:
print row[1]
输出:
Python is a program language
我创建了一个名称为 table 的测试数据库,其中有两列分别名为 Words 和 Sentences,我想在数据库 (sqlite3) 中搜索是否存在数据或单词or not,如果有那么系统会输出/打印 from table sentence 。我对这部分感到困惑。我试着编写这段代码,但它没有出现我想要的结果。
import sqlite3 as lite
import sys
connection = lite.connect('test.db')
with con:
cur = con.cursore()
cur execute("Select words From test")
inpt = "what the meaning of python ?"
for word in stn.split():
if word in words:
print Sentence
我把一个句子分成几个单词,然后在数据库中搜索,变量inpt中的单词是否在单词列中,如果有则系统将打印列句子。
我创建了一个这样的数据库:
words Sentences
---------- -------------------
Python Python is a program language
Django web framework for python
我想这就是您要找的。
import sqlite3 as lite
con = lite.connect('test.db')
with con:
cur = con.cursor()
for row in cur.execute("Select words, Sentences From test"):
inpt = "what the meaning of Python ?"
if row[0] in inpt:
print row[1]
输出:
Python is a program language