Initial working directory?
In Pythonista my app resides in its own folder ("Book Notes"). While doing the initial testing, of course, the initial working directory when running the app was always the same, since I was always starting up from the same .py file.
Now that I’ve saved my app to the home screen, it seems to sometimes start up with the initial working directory set to the folder the app’s main file is in; and sometimes with the initial working directory set to Pythonista’s Documents folder (Pythonista3/Documents).
So what I do currently is check to see if the current working directory ends in "/Book Notes", and if it does not, using os.chdir to change into "/Book Notes".
Is there something else I should be doing to ensure a consistent initial working directory?
The middle line should be all you need at the start of your script.
print(os.path.abspath(os.curdir)) os.chdir(os.path.expanduser('~/Documents/Book Notes')) print(os.path.abspath(os.curdir))
You could also just use
os.path.dirname(__file__)- assuming your interpreted file lies in your Book Notes folder. This would have the advantage of not having to hard code any folder name.
Thanks. Both of these work great.