Mentre io pensavo ad una intro simpatica "Peter Hansen" scriveva:
> 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... That's true :-D But as I said in the other post os.environ["HOME"] doesn't work on my Win2000 box. > 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. If you look at ntpath.py (I think this is the 'path' module on Windows 2000) in you Lib dir you'll see that expanduser does try os.environ["HOME"] So I'm not ignoring it, maybe it is redundant in my function. The problem is that expanduser and user.home doesn't test if the value returned is really a directory. > 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! :-) on my box it returns "%USERPROFILE%" ;-) -- Forgive your enemies, but never forget their names. |\ | |HomePage : http://nem01.altervista.org | \|emesis |XPN (my nr): http://xpn.altervista.org -- http://mail.python.org/mailman/listinfo/python-list