Python 3.0b2 cannot map '\u12b'

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Mon Sep 1 14:19:15 CEST 2008


On Mon, 01 Sep 2008 02:27:54 -0400, Terry Reedy wrote:

> I doubt the OP 'chose' cp437.  Why does Python using cp437 even when the
> default encoding is utf-8?
> 
> On WinXP
>  >>> sys.getdefaultencoding()
> 'utf-8'
>  >>> s='\u012b'
>  >>> s
> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
>    File "C:\Program Files\Python30\lib\io.py", line 1428, in write
>      b = encoder.encode(s)
>    File "C:\Program Files\Python30\lib\encodings\cp437.py", line 19, in
> encode
>      return codecs.charmap_encode(input,self.errors,encoding_map)[0]
> UnicodeEncodeError: 'charmap' codec can't encode character '\u012b' in
> position
> 1: character maps to <undefined>

Most likely because Python figured out that the terminal expects cp437.  
What does `sys.stdout.encoding` say?

> To put it another way, how can one 'choose' utf-8 for display to screen?

If the terminal expects cp437 then displaying utf-8 might give some 
problems.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list