May-15-2018, 05:55 PM
I'm working on a small program to keep track of library books and I'm doing the program in python3 and sqlite3. I'm not very far into the program at all and at the moment I just need to validate my sqlite3 table creation code is working. How can can I see a list of table for my sqlite3 database using python3, and I'd like to be able to see that table sctructure as well.
main.py
main.py
import db db.setup_db() db.conn input("Press any key to continue")db.py
import sqlite3 import os def setup_db(): directory = "C:\\Users\\me\\librarydb" if not os.path.exists(directory): print("directory does not exist") os.mkdir(directory) #conn = sqlite3.connect(r"C:\\Users\\me\\librarydb\\booksdb") build_db() else: print("directory exists") dbfile = "C:\\Users\\me\\librarydb\\booksdb" if not os.path.exists(dbfile): #conn = sqlite3.connect(r"C:\\Users\\me\\librarydb\\booksdb") build_db() def build_db(): conn = sqlite3.connect(r"C:\\Users\\me\\librarydb\\booksdb") c = conn.cursor() c.execute('''CREATE TABLE Books (book_id int, author_id int, book_title varchar(100), genre varchar(50), type varchar(30), cover char, price real)''') conn.commit() conn.close()