2015-07-03 67 views
0
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) 

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

但是沒有任何表格..如何獲取表格名稱?如何在python3上顯示在sqlite數據庫中創建的所有表格

+0

您打印'x'不'y'。將其更改爲'print(y)' – IanAuld

+0

我的錯誤...非常感謝Ian指出 –

回答

0

你需要從查詢獲取結果:

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) 
相關問題