Getting the home directory in Python and a bug in os.path.expanduser
diener896092_no_spam_here at bellsouth.net
Sat Jul 7 06:28:08 CEST 2007
What is the generic operating system way of getting the home directory ?
I am guessing it is os.path.expanduser("~"). Is there a better way or an
alternate way ?
If it is as I surmise, the aforementioned expanduser("~") of os.path
seems incorrect to me under Windows. The document says:
"On Windows, only "~" is supported; it is replaced by the environment
variable HOME or by a combination of HOMEDRIVE and HOMEPATH."
But HOME is never the home directory for Windows, only the combination
of HOMEDRIVE and HOMEPATH is valid, which is always set. If MSYS is
installed under Windows, where HOME must be set to the MSYS home
directory for a given user in order to emulate Linux/Unix, attempting to
use os.path.expanduser("~") will incorrectly return the MSYS home
directory for a given user rather than the Windows home directory for
the logged in user. So I think the os.path.expanduser("~") works
incorrectly in this case and needs to be fixed, else you are telling
users never to use MSYS under Windows.
More information about the Python-list