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

问题描述 投票:0回答:1
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
**************************************

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

python sqlite
1个回答
3
投票

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

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)
© www.soinside.com 2019 - 2024. All rights reserved.