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")

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.

better
way:

import sqlite3
conn = sqlite3.connect('examble.db')
conn.execute('That SQL code')
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.