Path ... where is my application's home dir?
Yermat
loic at yermat.net1.nerim.net
Wed Apr 28 15:17:17 EDT 2004
Duncan Booth a écrit :
> Tim Golden <tim.golden at viacom-outdoor.co.uk> wrote in
> news:mailman.81.1083164606.25742.python-list at python.org:
>
>
>>>And yes, the best place to store this information would be in
>>>the user's
>>>home dir, but then: Where is it? How to find it under Windows - every
>>>version of windows changes the place for home dirs. It would
>>>be nice to
>>>have something like this in a system/version independet way:
>>>
>>>sys.users_home_dir
>>>
>>>Is there anything like it in Python?
>>
>>There's nothing that strictly does that. You could
>>use os.path.expanduser ("~") but in Windows (at least
>>on my Win2K box) it returns "c:/" which is just about
>>acceptable for a one-user machine, but obviously not
>>for multi-user.
>>
>>The usual way to do this on Windows is to use the
>>winshell functions from pywin32:
>>
>><code>
>>from win32com.shell import shell, shellcon
>>print shell.SHGetPathFromIDList (
>> shell.SHGetSpecialFolderLocation (0, shellcon.CSIDL_APPDATA)
>>)
>></code>
>>
>>which, on my machine, gives:
>>
>>C:\Documents and Settings\goldent\Application Data
>
>
> A simpler way to get the same information:
>
> import os
> print os.environ['APPDATA']
>
And for the user dir, you can do (at least on Win2000, not try elsewhere) :
os.getenv('HOMEDRIVE') + os.getenv('HOMEPATH')
--
Yermat
More information about the Python-list
mailing list