Python 3.0b2 cannot map '\u12b'

josh logan dear.jay.logan at gmail.com
Mon Sep 1 09:00:00 EDT 2008


On Sep 1, 8:19 am, Marc 'BlackJack' Rintsch <bj_... at gmx.net> wrote:
> 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

So, it is not a problem with the program, but a problem when I print
it out.
sys.stdout.encoding does say cp437.

Now, when I don't print anything out, the program hangs. I will try
this again and let the board know the results.

Thanks for all of your insight.



More information about the Python-list mailing list