Windows XP - Environment variable - Unicode

John Roth newsgroups at
Sat Jul 12 13:47:55 CEST 2003

"sebastien.hugues" <sebastien.hugues at> wrote in message
news:3f0e77fc at
> 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
> 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,
> i am not able to find out what encoding is used when i make:
> appdata = os.environ ['APPDATA']
> Any ideas ?

I don't think encoding is an issue. Windows XP stores all character data as
unicode internally, so whatever you get back from os.environ() is either
going to be unicode, or it's going to be translated back to some single byte
code by Python. In the latter case, you may not be able to recover non-ascii
values, so Rob Willscroft's workaround to get the unicode version may be
your only hope.

If you're getting a standard string though, I'd try using Latin-1, or the
equivalent first (it's got an additional 32 characters that aren't in
Sorry I don't remember the actual names.

Note that Release 2.3 fixes the unicode problems for files under XP.
It's currently in late beta, though. I don't know if it fixes the
interface though, and it's rather late to get anything into 2.3.

John Roth

> Thanks in advance
> Sebastien

More information about the Python-list mailing list