python - Python sqlite 查询在终端中工作,但不能作为 exe
问题描述
我正在编写一个从 sqlite 数据库中提取用户信息的 Python 脚本。当我在终端中手动运行脚本时,我的查询有效。但是当我将脚本作为可执行文件运行时,sqlite 返回一个操作错误。
代码:
import datetime
import sqlite3
def get_user_info():
user_id = input("type the user's id number:")
# connect with the database
connection = sqlite3.connect('test.db')
# sql query
query = '''
SELECT *
FROM c_list
WHERE user_id = ?
'''
crsr = connection.execute(query, (user_id))
for row in crsr:
print("Username : ", row[0])
print("User ID :", row[1])
print("Book(s) checked out :", row[2])
print("Date checked out :", row[3])
print("\n")
connection.commit()
connection.close()
answer = input("would you like to return a book?")
if answer == 'yes':
return_book()
else:
exit()
get_user_info()
错误:
Traceback (most recent call last):
File "test.py", line 42, in <module>
File "test.py", line 24, in get_user_info
sqlite3.OperationalError: no such table: c_list
[7892] Failed to execute script test
解决方案
推荐阅读
- c - ioctl 调用总是返回 -1,但仍然有效
- javascript - Angular Routes 不接受 json 数组路由
- jquery - 在 JQuery 中的 hr 元素上使用悬停功能
- c++ - C ++在哪里可以找到boost源包中BOOST_LOG宏的实现
- c - 字符串没有被比较?还是输入正确?
- javascript - 用图像替换井字游戏中的 X 和 O
- dockerfile - 为什么 Kaniko 不能推送多阶段 Docker Image?
- html - 侧边栏宽度无法调整
- babeljs - babel-preset-env 安装失败
- javascript - 如何访问在 v-if 中条件渲染的 ref 元素 - Vue