Windows XP - Environment variable - Unicode

Rob Williscroft rtw at freenet.REMOVE.co.uk
Fri Jul 11 13:51:30 EDT 2003


sebastien.hugues wrote in news:3f0e77fc at epflnews.epfl.ch:

> Hi
> 
> I would like to retrieve the application data directory path of the 
> logged user on
> windows XP. To achieve this goal i use the environment variable
> APPDATA.
> 
> The logged user has this name: sébastien. The second character is not
> an ascii one and when i try to encode the path that contains this name
> in utf-8,
> i got this error:
> 
> Ascii error: index not in range (128)
> 
> I would like to first decode this string and then re-encode it in
> utf-8, but i am not able to find out what encoding is used when i
> make: 
> 
> appdata = os.environ ['APPDATA']
> 
> Any ideas ?
> 

I don't know if it will help but:

>>> import win32com.client
>>> shell = win32com.client.Dispatch("WScript.Shell")
>>> env = shell.GetEnvironment("VOLATILE")

>>> j = []
>>> for i in env:
...     j.append(i)
...     
>>> j
[u'LOGONSERVER=\\\\COMPUTERNAME', u'APPDATA=C:\\Documents and Settings
\\username\\Application Data']
>>> 

Note the leading u, which I don't get with:

>>> import os
>>> os.environ["APPDATA"]
'C:\\Documents and Settings\\username\\Application Data'

Also note that APPDATA should also be in 
>>> env = shell.GetEnvironment("PROCESS")

HTH

Rob.
-- 
http://www.victim-prime.dsl.pipex.com/




More information about the Python-list mailing list