Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to put a config file for a compiled Python script? [duplicate]

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 ?

like image 475
endolith Avatar asked Sep 21 '26 11:09

endolith


2 Answers

You can use the appdirs module to determine the appropriate folder for user data.

like image 63
Janne Karila Avatar answered Sep 24 '26 05:09

Janne Karila


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.

like image 22
Seth Avatar answered Sep 24 '26 05:09

Seth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!