[ Application's Datapath - os.environ ]
I am developing a Python Desktop application and I have been able to get it to work just fine, I am just having trouble getting classes to locate the database.
This application was build on the Windows platform and used the following code to create the database.
appDataPath = os.environ["APPDATA"] + "\\FolderName\\"
However, in mac, there is no APPDATA and I have been using HOME instead, but it creates the files on build as FolderNameapplication.db which is a real hassle.
The database is now residing on the Desktop (HOME) after removing the `"\FolderName\" extension and I need the appDataPath variable to point at the database. How can I achieve this?
Thanks
Answer 1
Use os.path.join()
to construct paths. OS X (and Linux) don't use backslashes for paths like Windows does so adding those strings with hard-coded path separators will cause you problems. (Although forward slashes can work on Windows...)
Example: os.path.join(os.environ['HOME'], 'somedir', 'mydb.db')
The usual OS X alternative to appdata is ~/Library/Application Support/appname/