Python Forum
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Small sqlite3 program error
#1
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.
Reply
#2
Change your main.py to

import db
 
db.setup_db()
 
input("Press any key to continue")
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Try running it from the console, so you can see the error.
Reply
#4
(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.
Reply
#5
do as nilamo suggests, and run from console so you can see what the error message is.
Reply
#6
(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!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  sqlite3 Conn Insert Value Error TylerDunbar 3 753 Sep-04-2023, 06:32 PM
Last Post: deanhystad
Question Using SQLAlchemy, prevent SQLite3 table update by multiple program instances Calab 3 758 Aug-09-2023, 05:51 PM
Last Post: Calab
  sqlite3.OperationalError: near "=": syntax error Maryan 1 5,644 Oct-31-2020, 12:09 AM
Last Post: Maryan
  sqlite3 database does not save data across restarting the program SheeppOSU 1 3,455 Jul-24-2020, 05:53 AM
Last Post: SheeppOSU
  Small Database Program (Need Help) thewetmosquito 3 2,200 Jul-11-2020, 01:51 PM
Last Post: menator01
  program error Dalpi 4 2,485 Apr-30-2020, 11:46 PM
Last Post: Dalpi
  Pyhton Coding Help Needed (very small error) friduk 2 2,459 Oct-23-2019, 08:41 AM
Last Post: Gribouillis
  sqlite3.OperationalError: near "%": syntax error Linuxdesire 2 18,048 Oct-13-2019, 02:54 AM
Last Post: Linuxdesire
  Program gives error but doesn't say where the error is. FWendeburg 3 2,815 Mar-09-2019, 11:42 PM
Last Post: FWendeburg
  sqlite3 operational error on insert query jonesin1974 5 4,304 Jun-26-2018, 03:31 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020