Python STILL prints the wrong international letters

John Machin machin_john_888 at hotmail.com
Fri May 18 20:19:49 EDT 2001


David LeBlanc <whisper at oz.nospamnet> wrote in message news:<9e3nda$eb5$k at 216.39.170.247>...
> It seems reasonable to me that the encoding the GUI is using is not the 
> same that the console is using - dunno why. In Tcl there are ways to set 
> the encoding of an incoming stream - is there the like in Python?
> 

This is true but *not* reasonable. Windows ("GUI") uses a different
code page to DOS ("console").

Try this:

>>> print chr(163)

On a bog-standard (US/UK/AU/etc) Windows system, you will see a "pound
sign" symbol if you are in Idle or Pythonwin or whatever (Windows
codepage 1252), and a "Latin small letter u with acute" symbol if you
are in a DOS ("Command Prompt" or "MS-DOS Prompt") window (codepage
850).

This rottenness is not confined to the state of Denmark, not is it
caused by Python.

OK, enough ranting. This may help:

Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>> pound = u"\u00a3"
>>> pound
u'\xa3'
>>> pound.encode("CP850")
'\x9c'
>>> pound.encode("CP1252")
'\xa3'
>>> unicode(chr(163), "CP850")
u'\xfa'
>>> unicode(chr(163), "CP1252")
u'\xa3'
>>>

What I don't know is how to determine what the current codepage is.
It's not in os.environ ...

The locale module doesn't seem to be of much help here; it tells me
'cp1252' even in a DOS window:

>>> import locale
>>> locale.getdefaultlocale()
('en_AU', 'cp1252')
>>>


Cheers,
John



More information about the Python-list mailing list