As mentioned in this related question, os.path.expanduser
or pathlib.Path.home()
can be used to get a path to the user home directory.
If a Python module needs to store some data, it will normally be stored somewhere in this directory, but the relative path to an appropriate location may vary by operating system. Programs running on Linux systems will typically store their settings and other data in a directory under ~/.local/share
or in a dot-file directly under the home directory. In Windows, this data normally gets stored under $HOME\AppData
if I recall correctly. Under macOS, the directory would be located under ~/Library/Application Support
.
Is there a standard library module or third-party package available that will make it possible to do something like:
import homedir_storage
app_directory = homedir_storage.get_package_storage_dir('my_package_name')
sqlite3.connect(os.path.join(app_directory, "db.sqlite"))
Where homedir_storage
represents the name of the hypothetical module/package?