Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Special Characters in Console

Reply
Thread Tools

Special Characters in Console

 
 
Gregor
Guest
Posts: n/a
 
      10-01-2003
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 "Mdchen"
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?

Thanks,

Greg
 
Reply With Quote
 
 
 
 
Gregor
Guest
Posts: n/a
 
      10-01-2003
I forgot to mention, I'm using Python on Windows...


Gregor <(E-Mail Removed)> wrote in news:ObHeb.1385$6C4.1108
@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 "Mdchen"
> 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?
>
> Thanks,
>
> Greg
>


 
Reply With Quote
 
 
 
 
Neil Hodgson
Guest
Posts: n/a
 
      10-01-2003
Gregor:

> 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 "Mdchen"
> 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?


The windows console is generally using the "Terminal" font with the "DOS:
Western Europe" character set which displays \xE4 as capital sigma. I don't
know of an encoding that matches this.

Neil


 
Reply With Quote
 
Martin v. =?iso-8859-15?q?L=F6wis?=
Guest
Posts: n/a
 
      10-01-2003
"Neil Hodgson" <(E-Mail Removed)> writes:

> The windows console is generally using the "Terminal" font with the "DOS:
> Western Europe" character set which displays \xE4 as capital sigma. I don't
> know of an encoding that matches this.


In Python 2.3, using a Unicode string should make it work "out of the
box". The code page is cp850, but printing on sys.stdout will
automatically convert to the terminal encoding, so application
knowledge about the terminal encoding is not needed.

Regards,
Martin
 
Reply With Quote
 
Bernard Delme
Guest
Posts: n/a
 
      10-01-2003
> # -*- coding: latin_1 -*-
>
> print "Mdchen"
> print "M\xE4dchen"
>
> Both statements produce a capital sigma where they should be. Typing
> "\xE4" directly in the console also spits back a sigma.


On the other hand if you capture the output in a file and then load
it in notepad/vim/pythonwin, you'll see that they look as expected...

> What encoding does the console use? Is there a way to get it to use
> latin-1?


Not that I know of. You might be interested in the win32 port
of the rxvt terminal which is bundled with the MSYS subproject
of the MINGW win32 port of gcc:

http://sourceforge.net/project/showf...?group_id=2435

Regards,

Bernard.



 
Reply With Quote
 
Duncan Booth
Guest
Posts: n/a
 
      10-02-2003
Gregor <(E-Mail Removed)> wrote in
news:ObHeb.1385$6C4.1108@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 "Mdchen"
> 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 http://www.velocityreviews.com/forums/(E-Mail Removed)
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?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Counting utf-8 characters -special characters majna Javascript 4 09-19-2007 01:53 PM
Remove only special characters and junk characters from a file rvino Perl 0 08-14-2007 07:23 AM
Re: Meta-Characters, Special Characters xah@xahlee.org Java 2 05-31-2007 09:25 AM
How to convert HTML special characters to the real characters with a Java script Stefan Mueller HTML 3 07-23-2006 10:09 PM
Special editions and Deluxe special edition dvd question. Rclrk43 DVD Video 8 12-29-2004 07:32 PM



Advertisments