473,398 Members | 2,403 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,398 software developers and data experts.

Foreign characters

How do I get Python to work with foreign characters? When I try to
print them, I get a unicode error (characters not ASCII). Wasn't
unicode invented for the express purpose of working with non-ASCII
characters?
Jul 18 '05 #1
3 3283
Tetsuo wrote:

How do I get Python to work with foreign characters? When I try to
print them, I get a unicode error (characters not ASCII). Wasn't
unicode invented for the express purpose of working with non-ASCII
characters?


The FAQ might help:

http://www.python.org/cgi-bin/faqw.p...=faq04.102.htp

-Peter
Jul 18 '05 #2
ts*********@softhome.net (Tetsuo) wrote in message news:<f4**************************@posting.google. com>...
How do I get Python to work with foreign characters? When I try to
print them, I get a unicode error (characters not ASCII).


# -*- coding: latin-1 -*-
greeting = "¡Hola! ¿Cómo estás?"
print greeting

Or if you actually need to use Unicode strings:

unicodeString = "a byte string".decode('encoding')
print unicodeString.encode('encoding')
Jul 18 '05 #3
ts*********@softhome.net (Tetsuo) wrote in message news:<f4**************************@posting.google. com>...
How do I get Python to work with foreign characters? When I try to
print them, I get a unicode error (characters not ASCII). Wasn't
unicode invented for the express purpose of working with non-ASCII
characters?


Erm, yes. But the problem you're having is undoubtedly occurring when
you try to send the Unicode data to your console or terminal. I'd
recommend using the encode method on your Unicode objects as described
in the thread "Characters in Python" - use groups.google.com to find
that discussion.

On the other hand, if you're using IDLE, I'd suggest trying out
IDLEfork if you really want to be able to send Unicode data straight
to the output window. IDLE in Python 2.2.x and below seems to have had
various issues with Unicode and output, but that's discussed in that
thread I mentioned.

I note that the content of the most relevant entry in the Python FAQ
can be regarded as being somewhat confusing:

http://www.python.org/cgi-bin/faqw.p...=faq04.102.htp

Notably this statement (in the context of the classic UnicodeError):

"This error indicates that your Python installation can handle only
7-bit ASCII strings."

I doubt that even if one makes the distinction between strings and
Unicode objects, as I often do myself, that Python has ever been
unable to handle 8-bit strings. Moreover, the statement gives the
impression that various Python installations exist which know about
Unicode (and related encodings) but can't deal with it. Perhaps the
entry ought to be updated with some of the tips given in previous
threads, and that more questions and answers need adding to the FAQ
(which I'm happy to do, by the way, if it's seen as being worthwhile).

Paul
Jul 18 '05 #4

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

Similar topics

4
by: Toffe | last post by:
Hi, I've got a problem with regular expressions and strings containing Swedish characters (åäö). I basically have a PHP script that highlights certain words in a text. I found the code...
0
by: JJY | last post by:
Hi. I have an ASP page. In there, I retirieve some data (Korean characters for testing purpose) from the database and I tried to display it. If I set the session.codepage = 949, the foreign...
1
by: dalei | last post by:
I like to make foreign letters to appear in the textarea. For instance, when typing the letter 'a' on the keyboard, the Japanese letter &#+12449; would appear in the textarea. Could somebody...
13
by: Xah Lee | last post by:
the Journey of Foreign Characters thru Internet Xah Lee, 20051101 There's a bunch of confusions about the display of non-ascii characters such as the bullet "•". These confusions are...
2
by: Harley | last post by:
im working on an ASP.NET app in VB.NET and have problems with foreign characters. everything works ok, special characters are presented ok onscreen when typed in the body of the page, using html...
16
by: Hugh Janus | last post by:
Hi all, I posted a couple of weeks ago with what I thought was a problem with the file system reading accented characters however, after debugging line by line I have now found the true problem....
3
by: =?Utf-8?B?R2VyaGFyZA==?= | last post by:
I get an error on a .net 2.0 page when I use foreign characters, such as ç or ã. Setting validateRequest=false handles this, but is there a way to keep validateRequest=true but allow foreign...
1
by: niklang | last post by:
Hi everybody, I have an ASP page that uses the MSXML2.ServerXMLHTTP object to read a stylesheet from IIS as follows: strXSLPath = "http://localhost/ej/ejdetail.xsl.asp" ...
3
by: MitchellEr | last post by:
I can't seem to get consistency in my application with foreign character handling. I'm creating a series of forms that update database tables. So, when trying to edit a form, the field values that...
5
by: Matt | last post by:
I originally posted this in microsoft.public.sqlserver.server, and it was suggested that I post here. I'm having problems with searches via a classic ASP front-end of terms including foreign...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
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
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...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.