Best practice for custom settings in $ HOME in Python

For some small programs in Python, I would like to install, save and get user settings in a file in a portable (multi-platform) way.

I am thinking of a very simple ConfigParser file, for example, "~ / .program" or "~ / .program / program.cfg".

Is there a os.path.expanduser()better way to achieve this, or is there something easier / more straightforward?

+3
source share
2 answers
os.path.expanduser("~")

more portable than

os.environ['HOME']

therefore it should be ok to use the first one.

+8
source

You can use os.environ:

import os
print os.environ["HOME"]
0
source

Source: https://habr.com/ru/post/1709170/


All Articles