Unicode issue on Windows cmd line

Benjamin Kaplan benjamin.kaplan at case.edu
Wed Feb 11 15:08:50 EST 2009


On Wed, Feb 11, 2009 at 2:50 PM, jeffg <jeffgemail at gmail.com> wrote:

> On Feb 11, 2:35 pm, Albert Hopkins <mar... at letterboxes.org> wrote:
> > On Wed, 2009-02-11 at 10:35 -0800, jeffg wrote:
> > > Having issue on Windows cmd.
> > > > Python.exe
> > > >>>a = u'\xf0'
> > > >>>print a
> >
> > > This gives a unicode error.
> >
> > > Works fine in IDLE, PythonWin, and my Macbook but I need to run this
> > > from a windows batch.
> >
> > > Character should look like this "ð".
> >
> > > Please help!
> >
> > You forgot to paste the error.
>
> The error looks like this:
>    File "<stdin", line 1, in <module>
>    File "C:\python25\lib\encodings\cp437.py", line 12, in encode
>      return codecs.charmap_encode(input,errors,encoding_map)
> UnicodeEncodeError: 'charmap' codec can't encode character u'\xf0' in
> position 0
> : character maps to <undefined>
>
>
> Running Python 2.5.4 on Windows XP



That isn't a python problem, it's a Windows problem. For "compatibility
reasons", Microsoft never added Unicode support to cmd.  When you do print
u'', python tries to convert the characters to the console encoding (the
really old cp437, not even the Windows standard cp1252), it messes up.
AFAIK, you'll have to use the chcp command to switch to an encoding that has
the character and then print u'\xf0'.encode(the_encoding) to get it to
display. There isn't any way around it- we've tried.


> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090211/bc89d72b/attachment.html>


More information about the Python-list mailing list