Special Characters in Console
Duncan Booth
duncan at NOSPAMrcp.co.uk
Thu Oct 2 06:33:13 EDT 2003
Gregor <palam_POOP_edes at softhome.net> wrote in
news:ObHeb.1385$6C4.1108 at pd7tw1no:
> I am trying to print some special characters, but they come out as
> different characters in the Python console. If I have a script like this:
>
> # -*- coding: latin_1 -*-
>
> print "Mädchen"
> print "M\xE4dchen"
>
> Both statements produce a capital sigma where they ä should be. Typing
> "\xE4" directly in the console also spits back a sigma.
>
> What encoding does the console use? Is there a way to get it to use
> latin-1?
... plus
> I forgot to mention, I'm using Python on Windows...
Assuming a console running in a window (as opposed to running fullscreen)
then you need to do two things:
1. The default raster font used for console windows doesn't know about
latin-1, so change it. Use the system menu, Properties and select "Lucida
Console" instead of "Raster Fonts".
2. Use the CHCP command to select the Latin-1 codepage: CHCP 1252
Now rerun your script and you should see the correct characters.
Alternatively:
print "M\xE4dchen".decode('latin1').encode('cp437')
will get your desired output on codepage 437.
--
Duncan Booth duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
More information about the Python-list
mailing list