confused genius
confused genius

Reputation: 3284

How to display all the tables created in sqlite database on python3

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
**************************************

But not any tables ... How to get the table names ?

Upvotes: 1

Views: 4532

Answers (1)

hiro protagonist
hiro protagonist

Reputation: 46921

you need to fetch the results from the query:

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)

Upvotes: 3

Related Questions