Windows XP - Environment variable - Unicode

"Martin v. Löwis" martin at v.loewis.de
Sat Jul 12 17:10:51 EDT 2003


John Roth wrote:

> 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. 

Read the source, Luke. Python uses environ, which is a C library 
variable pointing to byte strings, so no Unicode here.

 > 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.

You are certainly able to recover non-ascii values, as long as they
only use CP_ACP.

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

That, in general, is wrong. It is only true for the Western European and
American editions of Windows. In all other installations, CP_ACP differs
significantly from Latin-1.

> 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
> os.environ()

It doesn't. "Fixing" something here is less urgent and more difficult,
as environment variables rarely exceed CP_ACP.

If people get support for Unicode environment variables, they want 
Unicode command line arguments next.

Regards,
Martin





More information about the Python-list mailing list