locale.getdefaultlocale() encoding on Win32

Martin v. Löwis martin at v.loewis.de
Fri May 9 02:42:56 EDT 2003


"Paul Watson" <pwatson at redlinec.com> writes:

> Should the default locale encoding for python when running on
> Windows Latin-1 in a shell be cp437 rather than cp1252?

No. What does "running in a shell" actually mean? A program may "run
in a shell" and still create Windows.

> I believe that there may be an API to detect running in ANSI vs. OEM
> mode or to query the current codepage.

There is no such thing as "running in ANSI", so you can't detect it.
There is a way to determine the encoding of stdout if stdout is
associated with a console, see python.org/sf/612627.

> Clearly, cp1252 does not yield the desired conversion in the current
> process.

That is not all that clear. getdefaultlocale() does what it is
supposed to do, on Windows. The fact that there are *two* default
encoding in Windows is unfortunate, and not something you can deal
with by switching the return value of a function that assumes there is
only one from one to the other - then users expecting the other will
complain. In addition, returning CP_OEM might be wrong for the console
as well, as somebody may have changed the console encoding.

Regards,
Martin




More information about the Python-list mailing list