D90 #100DaysOfCode

D90 #100DaysOfCode. I fixed my todo application so it now can be set as an alias and be run from any directory 🙂 and just some general tweaks.

Read Time1 Minute, 4 Second

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.

0 0
Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleppy
Sleppy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

Leave a Reply

Your email address will not be published. Required fields are marked *

Close