473,804 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 9917
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******@bigpo nd.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@pd7tw 1no:
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".de code('latin1'). encode('cp437')

will get your desired output on codepage 437.

--
Duncan Booth du****@rcp.co.u k
int month(char *p){return(1248 64/((p[0]+p[1]-p[2]&0x1f)+1)%12 )["\5\x8\3"
"\6\7\xb\1\x9\x a\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
2200
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 characters. In my case the argument is a filename (eg. udtræk.xml). It seems like python tries to guess the encoding in which the arguments are passed, instead of just recieving them in unicode,
2
6282
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 declares these enitities and assigns them the correct unicodes (such as é) Now, when I've loaded the xml and converted it using the DOM and then Console.Writelined() it, it all looks good.
2
32500
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 remove these?
6
15548
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 characters and compare each character of string to the array? Thanks
5
8634
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". Same file path containing special characters works fine in one machine, but doesn't work in other. I am using following API function to get short file path. Declare Auto Function GetShortPathName Lib "kernel32" (ByVal lpszLongPath As
25
5394
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 out that addslashes() can be used escape some characters, but I'm having some more problems with for instance ä, å and µ (since the text is scientifical) Now some people also throw in htmlspecialchars() to convert those to HTML entities, but some...
3
10204
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. This is not a regular expression tutorial. Assumes you are already familiar with basic regular expression concepts and terminology. If not, you may want to read some regular expression tutorial. See the end of the article for links to online resources....
2
2364
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 (Internet Explorer). It displays something like $^^% instead of a comma. Please how can I have the browser display the comma as it is from the database.
9
2573
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: $ python -c "print '\033 ColorReset = os.environ Esc = os.environ print '%s%s%s%s%s' % (Esc, Color, " foo ", Esc, ColorReset)
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9595
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10604
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10359
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10101
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9177
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6870
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.