Unicode issue on Windows cmd line

Benjamin Kaplan benjamin.kaplan at case.edu
Wed Feb 11 17:35:57 EST 2009


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

> On Feb 11, 3:57 pm, "Martin v. Löwis" <mar... at v.loewis.de> 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!
> >
> > Well, your terminal just cannot display this character by default; you
> > need to use a different terminal program, or reconfigure your terminal.
> >
> > For example, do
> >
> > chcp 1252
> >
> > and select Lucida Console as the terminal font, then try again.
> >
> > Of course, this will cause *different* characters to become
> > non-displayable.
> >
> > Regards,
> > Martin
>
> Thanks, I ended up using encode('iso-8859-15', "replace")
> Perhaps more up to date than cp1252...??



> It still didn't print correctly, but it did write correctly, which was
> my main problem.


Let me guess, it showed up as *≡**. *This is the cp437 symbol at 0xf0.

When Python sends the string to stdout, it doesn't send characters, it sends
a stream of bytes. It is up to the file or file-like object at the other end
(in this case, cmd.exe) to interpret those bytes. Both cp1252 and
ISO-8859-15 interpret the byte /xf0 as ð. When you opened the text file, it
probbly opened as cp1252 because that's the Windows default. If you change
the terminal encoding, it will display correctly for the same reason.




> --
> 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/90fe3532/attachment.html>


More information about the Python-list mailing list