Finding user's home dir
Peter Hansen
peter at engcorp.com
Thu Feb 3 08:39:52 EST 2005
Miki Tebeka wrote:
>>Hi all, I'm trying to write a multiplatform function that tries to
>>return the actual user home directory.
>>...
>
> What's wrong with:
> from user import home
> which does about what your code does.
:-)
I suspect he simply didn't know about it. I didn't either...
Nemesis, please use the above recipe instead, as it makes
the more reasonable (IMHO) choice of checking for a HOME
environment variable before trying the expanduser("~")
approach. This covers folks like me who, though stuck
using Windows, despise the ridiculous Microsoft convention
of "user folders" named like "C:\Documents and Settings\Peter"
and prefer to create sensible folder like c:\users\peter
and set a HOME variable to point to it. Your approach
ignores our HOME variable.
c:\>python
Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32
>>> from user import home
>>> print home
c:\users\peter
Yay! :-)
-Peter
More information about the Python-list
mailing list