Python Forum

Full Version: Small sqlite3 program error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
main.py
import db

setup_db()

input("Press any key to continue")
db.py
import sqlite3
import os


def setup_db():
    directory = "C:\\Users\\bi18avi\\librarydb"

    if not os.path.exists(directory):
        print("directory does not exist")
        os.mkdir(directory)
        conn = sqlite3.connect(r"C:\\Users\\bi18avi\\librarydb\\booksdb")

    else:
        print("directory exists")
        dbfile = "C:\\Users\\bi18avi\\librarydb\\booksdb"
        if not os.path.exists(dbfile):
        conn = sqlite3.connect(r"C:\\Users\\bi18avi\\librarydb\\booksdb")
I'm running the above program on Windows 7 but it fails when I try to run the main.py script, the console box goes away so quick I can't see the error message. Note that it was working just fine when I had the db code in the main.py file running outside of a function. Any ideas as to what the problem is? Thanks.
Change your main.py to

import db
 
db.setup_db()
 
input("Press any key to continue")
Try running it from the console, so you can see the error.
(May-10-2018, 04:45 PM)buran Wrote: [ -> ]Change your main.py to

import db
 
db.setup_db()
 
input("Press any key to continue")

I changed setup.py() to db.setup_db() but I'm still getting a console that flashes and then disappears before I can see what's going on. I'm sure it's a different error now but I'm visibly getting the same thing.
do as nilamo suggests, and run from console so you can see what the error message is.
(May-10-2018, 05:28 PM)Larz60+ Wrote: [ -> ]do as nilamo suggests, and run from console so you can see what the error message is.
python is not recognized as an internal or external command, operable program or batch file

I'm guessing this has something to do with a python environment variable, I'm having to work with Windows and I have no idea what I'm doing in Windows.

SOLVED!