I want to create sqlite3 databases from within a python script.
I am currently running this code which does not pass the right variable content to the sqlite3 command prompt, so I have one issue there.
I also do not want to have the user have an sqlite3 command shell open. I just want to define the db, and have the tables created and populated later by the py script.
I don't want to use a default sqlite3 db for this application, because I want to be able to save instances related to specific data sets.

import csv
import sqlite3 as lite
import os

con = None

def main():
    choice = "chew"
    filename=raw_input("enter the filename==>  ")
    current_db = filename[:-4]+'.db' 
    print("The filename minus the extention is " + filename[:-4])
    print("This is the name of the current DB "  + current_db)
    os.system("sqlite3 $current_db")
3 Years
Discussion Span
Last Post by james.lu.75491856

I found a solution - it is using SQLAlchemy to set up the db.


Or - when you invoke the db in the sql module, let it create the table just like that. This was not in the documentation, at least not explicitly.

new_or_existing_connection = sqlite.connect(databasename.db)
# Whatever you call the db within the quotes is what you will create.
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.