locale.getdefaultlocale() encoding on Win32

Paul Watson pwatson at redlinec.com
Thu May 8 22:59:32 EDT 2003


Should the default locale encoding for python when running on Windows
Latin-1 in a shell be cp437 rather than cp1252?  I believe that there may be
an API to detect running in ANSI vs. OEM mode or to query the current
codepage.

$ python
Python 2.3b1 (#40, Apr 25 2003, 19:06:24) [MSC v.1200 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getlocale()
(None, None)
>>> locale.getdefaultlocale()
('en_US', 'cp1252')

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

>>> u=u'abc \xC7 def'
>>> u
u'abc \xc7 def'
>>> u.encode(locale.getdefaultlocale()[1])
'abc \xc7 def'
>>> print u.encode(locale.getdefaultlocale()[1])
abc ? def
>>> u.encode('cp437')
'abc \x80 def'
>>> print u.encode('cp437')
abc Ç def






More information about the Python-list mailing list