HOME Directory in posix and nt

Jarek Zgoda jzgoda at gazeta.usun.pl
Sun Aug 3 19:06:25 CEST 2003

Jeff Epler <jepler at unpythonic.net> pisze:

> os.environ holds the system environment, so
> 	home = os.environ['HOME'] 
> on unix, and 
> 	home = os.environ['HOMEPATH'] 
> on windows might be what you want.
> You could also try
> 	home = os.path.expanduser("~")
> which looks at HOME and pwd.getpwuid on unix, and at HOME, HOMEPATH, and

Unfortunately, the latest is known to give strange results on Windows
2000. On my machine at work (W2K Sp3) it just returns string
'%USERPROFILE%'. On my wife's WinXP Pro Sp1 it returns 'C:\', which is
crap, since home directory is set to 'C:\Documents and Settings...'
(that's the value of HOMEDRIVE + HOMEPATH and of USERPROFILE variables).

Jarek Zgoda
Registered Linux User #-1
http://www.zgoda.biz/ JID:zgoda at chrome.pl http://zgoda.jogger.pl/

More information about the Python-list mailing list