Cross-platform Method To Obtain The User's Configuration Home Directory In Python?
My program needs to store some configuration files. The major operating systems seems to have a designated location to place those; for instance, on Freedesktop.org compliant syste
Solution 1:
You can use the package appdirs
. This is developed by ActiveState who must have quite a lot of experience on cross-platform python.
import appdirs
appdirs.user_config_dir(appname='MyApp')
The package is just a single file (/module), so if you need it for a small script it is simple to just copy what you need. Otherwise the package is available with both pip
and conda
.
Solution 2:
import osprintos.path.expanduser("~/.my_config/data")
will always allow you to write ... config files are best stored where you want them
oftentimes on windows this is
os.path.expandvars("%appdata%/.my_config")
most other systems tend to put the in the userprofile director (~)
unless you are looking for a specific configuration file location(perhaps to interact with another software... in which case we would need to know which software)
Post a Comment for "Cross-platform Method To Obtain The User's Configuration Home Directory In Python?"