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 systems, it will be the path stored in the $XDG_CONFIG_HOME
environment variable.
Is there a method (or a library) to obtain this configuration home directory across the major operating systems: Windows, OS X, Linux?
expanduser() function in Python provides the most straightforward method for retrieving the user home directory across all platforms. The Python os module offers os. path. expanduser(") to retrieve the home directory.
A home directory is the directory or folder commonly given to a user on a network or Unix or Linux variant operating system. With the home directory the user can store all their personal information, files, login scripts, and user information.
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
.
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