473,386 Members | 1,602 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Special Characters in Console

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?

Thanks,

Greg
Jul 18 '05 #1
5 9873
I forgot to mention, I'm using Python on Windows...
Gregor <pa*************@softhome.net> 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 "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?

Thanks,

Greg


Jul 18 '05 #2
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 "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?


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
Jul 18 '05 #3
"Neil Hodgson" <nh******@bigpond.net.au> 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
Jul 18 '05 #4
> # -*- 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.
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.

Jul 18 '05 #5
Gregor <pa*************@softhome.net> 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 "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 du****@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?
Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: trapeze.jsg | last post by:
Hi. Platform: Win XP Python version: 2.4.1 Running script from: cmd.exe (windows console) I am having some trouble passing arguments to a python script having special...
2
by: nextman | last post by:
A guy called Yuri brought this up a while ago but no one got back to him and now I have the same problem. I have an xml file which contains special characters such as &eacute; etc. The DTD...
2
by: Mark Bosley | last post by:
i'm reading from a database and found special character showing up as \0 or &#x0;&#x0; when i serialize to xml. trim does not work and using the string.Replace doesn't either. how do i...
6
by: dwight | last post by:
I have a string that can't contain the following characters: ../\|}{[:;+=_)(*&^%$#@!~` What would be easiest way to check the string? Should I use regexp or create a array with these...
5
by: Sakharam Phapale | last post by:
Hi All, I am using an API function, which takes file path as an input. When file path contains special characters (@,#,$,%,&,^, etc), API function gives an error as "Unable to open input file"....
25
by: Wim Cossement | last post by:
Hello, I was wondering if there are a few good pages and/or examples on how to process form data correctly for putting it in a MySQL DB. Since I'm not used to using PHP a lot, I already found...
3
KevinADC
by: KevinADC | last post by:
Purpose The purpose of this article is to discuss the difference between characters inside a character class and outside a character class and some special characters inside a character class....
2
by: chike_oji | last post by:
Hello, I am displaying data retrieved from a database as a httpresponse in a webform. I noticed that some characters such as the comma (,), display as special characters in the web browser...
9
by: TP | last post by:
Hi everybody, I am new to Python, I try to understand how Python treats special characters. For example, if I execute the following line in a shell console, I obtain a colored string: $...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.