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 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
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
"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
> # -*- 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.
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? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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,
|
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 é
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.
|
by: Mark Bosley |
last post by:
i'm reading from a database and found special character showing up as \0
or
�� when i serialize to xml.
trim does not work and using the string.Replace doesn't either.
how do i remove these?
|
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
|
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
| |
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...
|
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....
|
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.
|
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)
|
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...
|
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,...
| |
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...
|
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,...
|
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...
|
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...
|
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();...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |