Re: Windows User path
Phillip Pearson <[email protected]> Tue, 13 Apr 2004 10:42:04 +1200
| Newsgroups | gmane.comp.pythin.pyds.devel |
|---|---|
| Message-ID | <[email protected]> |
xp: returns 'c:\\Documents and Settings\\phillipp' for me.
don't have access to nt or me systems, but may be able to get you 2k
and 98 results ...
also see the code:
def expanduser(path):
"""Expand ~ and ~user constructs.
If user or $HOME is unknown, do nothing."""
if path[:1] != '~':
return path
i, n = 1, len(path)
while i < n and path[i] not in '/\\':
i = i + 1
if i == 1:
if os.environ.has_key('HOME'):
userhome = os.environ['HOME']
elif not os.environ.has_key('HOMEPATH'):
return path
else:
try:
drive = os.environ['HOMEDRIVE']
except KeyError:
drive = ''
userhome = join(drive, os.environ['HOMEPATH'])
else:
return path
return userhome + path[i:]
cheers,
phil :)
On Mon, Apr 12, 2004 at 12:46:00PM +0200, Georg Bauer wrote:
> Hi!
>
> >Is this different from os.path.expanduser? ntpath.py's expanduser()
> >seems to contain the logic that people have been talking about here ...
>
> Ah, didn't remember that function. Sure, os.path.expanduser('~/')
> _should_ give a correct path, but I never tried that with Windows. Can
> somebody with different Windows versions please post what is returned by
>
> os.path.expanduser('~/')
>
> under at least the following systems:
>
> Windows 9x
> Windows ME
> Windows NT
> Windows 2000
> Windows XP
>
> (although I hope the last three behave mostly identically)
>
> bye, Georg
>