How to get table names using sqlite3 through pytho

2019-03-27 02:50发布

This question already has an answer here:

I have a problem to get data from the sqlite3 database. I can't find out the names of tables and their encoding. When I open DB through sqlitebrowser names were just unreadable characters. Connection to DB is fine.

conn = sqlite3.connect('my.db')
conn_cursor = conn.cursor()
conn.text_factory = str

But how can I get the names of tables and their encoding?

1条回答
做自己的国王
2楼-- · 2019-03-27 02:58

You can use this query to get tables names.

res = conn.execute("SELECT name FROM sqlite_master WHERE type='table';")
for name in res:
    print name[0]
查看更多
登录 后发表回答