我连接了sqlite,成功了。甚至将数据插入到表中,但在尝试获取并打印任何未显示的内容时。
import sqlite3
from sqlite3 import Error
def db_connect(db_file):
try:
conn=sqlite3.connect(db_file)
return conn
except Error as e:
print(e)
return conn
def db_operation(conn,str):
try:
c=conn.cursor()
c.execute(str)
res=c.fetchall()
for i in res:
print(i)
except Error as e:
print(e)
return res
if __name__=='__main__':
database=r'E:\sqlite\test.db'
conn=db_connect(database)
if conn:
print("enter the query")
str=input()
res=db_operation(conn,str)