Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

best practice for user preferences in $HOME in Python

For some small programs in Python, I would like to set, store and retrieve user preferences in a file in a portable (multi-platform) way.

I am thinking about a very simple ConfigParser file like "~/.program" or "~/.program/program.cfg".

Is os.path.expanduser() the best way for achieving this or is there something more easy/straightforward?

like image 640
steko Avatar asked Sep 16 '25 00:09

steko


1 Answers

os.path.expanduser("~")

is more portable than

os.environ['HOME']

so it should be ok to use the first.

like image 142
miku Avatar answered Sep 17 '25 14:09

miku