如何在python3上显示sqlite数据库中创建的所有表

mzillmmw  于 2023-10-23  发布在  SQLite
关注(0)|答案(1)|浏览(133)
import sqlite3
    
conn = sqlite3.connect('boo2.db')
c = conn.cursor()
    
x = c.execute("SELECT * FROM sqlite_master where type='table'")
    
for y in x:
    print(x)

输出是

********************************
<sqlite3.Cursor object at 0x00272DE0>
Process finished with exit code 0
**************************************

但不是任何table...如何获取表名?

8yparm6h

8yparm6h1#

你需要从查询中获取结果:

import sqlite3

conn = sqlite3.connect('boo2.db')
c = conn.cursor()

x=c.execute("SELECT * FROM sqlite_master where type='table'")

for y in x.fetchall():
    print(y)

相关问题