10 days left!
So I’ve been working on a new project which you will know about if you read my last post. I’m making a Todo list tracker that stores your data in an SQLite database.
I was having a few issues where if I set an alias for the application it couldn’t find the database, that’s because I was saying check in the current directory you are currently in for the database, rather than a fixed directory.
I managed to come up with a fix for this:
appPath = os.path.dirname(os.path.abspath( __file__ )) dbPath = os.path.join(appPath, 'notes.db')
So this states that the application path is set at the path where the application is running from, and the database path can be found in the same directory but is called ‘notes.db’
I then told my dbCheck function to look there:
def dbCheck(): if os.path.isfile(dbPath) == False: dbChoice = input("Database notes.db was not found, would you like to create a new Database? [Y],[N]").lower() if dbChoice == 'y': dbCreate() elif dbChoice == 'n': exit(0) elif os.path.isfile(dbPath) == True: #print("Database was found...") return
Let me show you it in action running from any directory, note that there is no notes.db in the directory I’m running ‘todo’ from.