python 数据库操作

找不到表的问题

sqlite3.OperationalError: no such table: canbox

// 问题代码, DB文件和PY文件同级的,但是不知道为什么没有对应的表
db = sqlite3.connect("canbus.db")

可能是文件路径没有找到,导致打开的文件不对,数据库是空的

import os

BASE_DIR =  os.path.dirname(__file__)  
db_path = os.path.join(BASE_DIR, "canbus.db")
print ("@##",db_path)
db = sqlite3.connect(db_path)

获取数据库中所有的表名

select name from sqlite_master where type = 'table' order by name;

针对connect对象的统计


相关的sqlite3 的python处理网址
https://docs.python.org/3/library/sqlite3.html