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)

the output is

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

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

2
  • You are printing x not y. change it to print(y) Commented Jul 3, 2015 at 14:18
  • My Bad ...Thanks a lot Ian for pointing out Commented Jul 3, 2015 at 14:26

1 Answer 1

3

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.