Skip to content

Commit 823af1b

Browse files
committed
Added DB file path code
this code handles different working directories on Mac's and Windows machines in case someone runs the code from a directory that is not matching the current working directory
1 parent 6774dcd commit 823af1b

3 files changed

Lines changed: 4 additions & 1 deletion

File tree

4 DB in Python/SQLite Demo/vinventory.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
#importing Error this way let's us refer to it by this name instead of sqlite3.Error
88
from sqlite3 import Error
99
import datetime
10-
database_file_path = "myinventory.db"
10+
#if you code is not connecting to the DB, uncomment the next three lines and read the comments. Also, you may need \ instead of / before the DB file name in windows
11+
#import os
12+
#path_root = os.path.dirname(os.path.abspath(__file__)) #grab the file system path to the current script file
13+
#database_file_path = str(path_root)+"/myinventory.db" #construct the path to the database file (only necessary if the current working directory is not the same as the folder where this Python file is located.)
1114

1215
def create_connection(db_file):
1316
""" create a database connection to the SQLite database

4 DB in Python/SQLite Demomyinventory.db

Whitespace-only changes.

myinventory.db

Whitespace-only changes.

0 commit comments

Comments
 (0)