问题
How to find current user home directory on OS X?
HOME
environmental variable is not always set, for example when you do not run in console (GUI apps).
For this reason I'm looking for a generic solution, one that will fall-back if os.environ['HOME']
is not set.
There is a similar question (C) but it already has an accepted solution that is invalid.
A Python solution would be preferred but other languages are welcome as long they provide a valid home or at least one location where you can write.
回答1:
It looks that os.path.expanduser("~")
always returns the home directory, even on Windows.
来源:https://stackoverflow.com/questions/3726113/getting-current-user-home-directory-on-os-x