This is similar to Where to put a configuration file in Python?, but I'm asking about scripts compiled/frozen with py2exe or similar on Windows systems. (Namely, this one: What config file format to use for user-friendly strings of arbitrary bytes? https://gist.github.com/1119561)
My first thought was to put the config file in the same folder as the .exe, which makes it sort of self-contained. But if I associate files with the .exe, it will be called from their directory, not its own, so I'd need something like How do I get the path of the current executed file in Python? to find the config file.
Is this the best way? Or is there some standard config file locations to search in, like https://stackoverflow.com/a/7567946/125507 ?
You can use the appdirs module to determine the appropriate folder for user data.
If this is a config file that the user is supposed to edit, then put it somewhere obvious. I tend "compile" python apps in a directory structure like this:
C:/path/to/Application
| config.ini
| Run Application.bat (runs code/application.exe)
| code/
| application.exe
| library.zip
| ... etc.
This keeps the "start the app" shortcut and the config file in the same place, easy for the user to find.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With