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

problem with cjkcodecs on Mandrake linux

The superuser of the Mandrake system in my lab
installed cjkcodecs for python.

But there is a problem.

I can encode english alphabets like 'a', 'b', 'c' or
'abc' like so:

s = 'abc'
s = unicode(s, 'gbk')
print s # prints 'abc'

but when I tried to encode Chinese strings, I have a
problem.

For example, to run the following script:

s = "蟒蛇" # 2 Chinese characters for
python
s = unicode(s, 'gbk')
print s

I get the following error message.

[antony@ancho tmp]$ python snake.py
Traceback (most recent call last):
File "snake.py", line 6, in ?
print a
UnicodeEncodeError: 'latin-1' codec can't encode
characters in position 0-1: ordinal not in range(256)
[antony@ancho tmp]$

What is the problem please?
__________________________________
Do you Yahoo!?
Yahoo! Mail - More reliable, more storage, less spam
http://mail.yahoo.com

Jul 18 '05 #1
3 1393
Anthony Liu wrote:
I get the following error message.

[antony@ancho tmp]$ python snake.py
Traceback (most recent call last):
File "snake.py", line 6, in ?
print a
UnicodeEncodeError: 'latin-1' codec can't encode
characters in position 0-1: ordinal not in range(256)
[antony@ancho tmp]$

What is the problem please?


The problem is the default encoding is Latin-1, presumably because
that's the only thing your xterm/virtual console understands. So Python
is rightly complaining that it can't print the Chinese characters for
you.

--
__ Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
/ \ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
\__/ In this world, nothing is certain but death and taxes.
-- Benjamin Franklin
Jul 18 '05 #2

Anthony> But I am using gbcxterm, which displays Chinese very well,
Anthony> plus, I think I can also input Chinese using this terminal.
Anthony> Then why do I still have this problem?

Look in your installed site.py file for the encoding variable and change it
as you like. The default is "ascii". Sounds like your sys admin may have
changed it to "latin-1".

Skip

Jul 18 '05 #3
Skip Montanaro <sk**@pobox.com> writes:
Anthony> But I am using gbcxterm, which displays Chinese very well,
Anthony> plus, I think I can also input Chinese using this terminal.
Anthony> Then why do I still have this problem?

Look in your installed site.py file for the encoding variable and change it
as you like. The default is "ascii". Sounds like your sys admin may have
changed it to "latin-1".


Nah, more likely is that he is using 2.3 which uses
locale.nl_langinfo(CODESET) to find out which encoding to use on
output.

Cheers,
mwh

--
(ps: don't feed the lawyers: they just lose their fear of humans)
-- Peter Wood, comp.lang.lisp
Jul 18 '05 #4

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

Similar topics

2
by: bouchia.nazha | last post by:
Hello I have encountered a problem using tomcat, linux and ssl. My problem seem to be a JVM memory deallocation problem on Linux. This is my configuration: OS: Redhat7.2 Tomcat: 4.0 Jdk:...
3
by: Joal Heagney | last post by:
Hi everyone. I've been getting this error message in python, and it's really driving me up the wall. $ python 'import site' failed; use -v for traceback Python 2.3.4 (#1, Apr 18 2005,...
2
by: javier garcia - CEBAS | last post by:
Please, disregard my last message. I've discovered that in "password" file it was mentioned a path '/var/lib/psql' where Mandrake distro installed postres previously. I've solved it. But I still...
6
by: kabrit | last post by:
Entrez "aide" pour afficher à nouveau les noms de produits. Entrez "quitter" pour quitter. *********************************************************** DB2.PE IBM_db2msen81... Preparing......
10
by: Rhino | last post by:
Has anyone managed to get DB2 V8.1 to install and run on Linux Mandrake 9.1/9.2? I know that IBM does not officially support DB2 on Mandrake but I also know that the clever people who buy DB2...
1
by: Eveline | last post by:
Hi all, I am trying to install IBM DB2 V8.1 on Mandrake Linux 10.1. Java is installed and when I try to run db2setup as a root, I get the following error: # ./db2setup DBI1190I db2setup is...
20
by: Shanta McBain | last post by:
Hi I am running Mandrake 10 and would like to get sql-ledger to access the database. I can get in to the database with a local user at the command prompt and Web Admin. sql-ledger returns...
12
by: Henryk | last post by:
Hey there, I have some problems with the following code snippet on a Virtex-4 PowerPC with a GCC based compiler char chData; sprintf(&chData, "%+05.0f", -0.038f); --I get "-000" ???...
6
by: sugapablo | last post by:
I have an old machine running Mandrake 9.2 and PHP 4.3.1 hosting several websites. With the coming changes to daylight savings time in March 2007, what are my options in correcting the current...
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
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,...
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...
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
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,...

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.