473,386 Members | 1,693 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.

how to show Chinese Characters in the value set of a dictionary

Hi there,
I have a dictionary with values of Chinses Characters. For
example,
dict = {}
dict['c1']="ä¸*国一"
dict['c2']="ä¸*国二"
dict.values()

['\xd6\xd0\xb9\xfa\xb6\xfe', '\xd6\xd0\xb9\xfa\xd2\xbb']

Since the result of dict.values will be inserted into web pages and
handled by javascript there, I want to show Chinese Characters
in the list directly like this,

['ä¸*国一','ä¸*国二']

Anybody knows how to do this? Thank you very much for your help.

Ouyang

Jan 1 '06 #1
4 2041
On Sun, 01 Jan 2006 07:35:31 -0800, zxo102 wrote:

Hi there,
I have a dictionary with values of Chinses Characters. For
example,
dict = {}
dict['c1']="ä¸*国一"
dict['c2']="ä¸*国二"
dict.values() ['\xd6\xd0\xb9\xfa\xb6\xfe', '\xd6\xd0\xb9\xfa\xd2\xbb']

Since the result of dict.values will be inserted into web pages and
handled by javascript there, I want to show Chinese Characters
in the list directly like this,

['ä¸*国一','ä¸*国二']

Anybody knows how to do this? Thank you very much for your help.

Ouyang

print "['", dict.values()[0], "']", "['", dict.values()[1], "']"

[' ä¸*国二 '] [' ä¸*国一 ']

Jan 1 '06 #2
zxo102 schrieb:
Hi there,
I have a dictionary with values of Chinses Characters. For
example,

dict = {}
dict['c1']="ä¸*国一"
dict['c2']="ä¸*国二"
dict.values()


['\xd6\xd0\xb9\xfa\xb6\xfe', '\xd6\xd0\xb9\xfa\xd2\xbb']

Since the result of dict.values will be inserted into web pages and
handled by javascript there, I want to show Chinese Characters
in the list directly like this,

['ä¸*国一','ä¸*国二']

Anybody knows how to do this? Thank you very much for your help.


I can see these chines characters very well - so I don't see why it
won't work putting them into a HTML page. Just nake sure you use the
proper encoding, most probably utf-8.

What put you off probably is the fact that in the interpreter, strings
are printed using their __repr__-method, that puts out those "funny"
hex-characters. But no need to worry there.

Additionally, you should use unicode-objecvts instead of byte-strings

do

# -*- coding: utf-8 -*-
d = dict(c1=u"ä¸*国一")

Notice the u in front of the string-literal.

Diez
Jan 1 '06 #3
In article <41*************@uni-berlin.de>,
"Diez B. Roggisch" <de***@nospam.web.de> wrote:
....
What put you off probably is the fact that in the interpreter, strings
are printed using their __repr__-method, that puts out those "funny"
hex-characters. But no need to worry there.


Moreover, the "print" statement also uses repr to convert lists
to strings.

If this generally suits your purposes, and you'd just prefer to avoid
the "escape" translation in strings, then I guess you either have to
write your own repr function for the lists, or for the strings. The
first option should be fairly straightforward. For the second, I'm
thinking of something like this -

class Xtring(types.StringType):
def __init__(self, a):
self.value = a
def __repr__(self):
return '¥'%s¥'' % self.value

dict['c1'] = Xtring('...')

print dict.values()

(Of course you should use unicode instead of string - if you can
figure out how to require the default encoding that supports
your character set. Python has an unfortunate preference for
"ascii" as a default encoding, and that's not likely to be the one
you want if you have any reason to use unicode.

Donn Cave, do**@u.washington.edu
Jan 3 '06 #4
On 1 Jan 2006 07:35:31 -0800, rumours say that "zxo102" <zx****@gmail.com>
might have written:
dict.values()

['\xd6\xd0\xb9\xfa\xb6\xfe', '\xd6\xd0\xb9\xfa\xd2\xbb']

Since the result of dict.values will be inserted into web pages and
handled by javascript there, I want to show Chinese Characters
in the list directly like this,

['???','???']


Diez's instructions were useful to you, however for quick previewing check
this recipe, it might be useful:

http://aspn.activestate.com/ASPN/Coo.../Recipe/439148
--
TZOTZIOY, I speak England very best.
"Dear Paul,
please stop spamming us."
The Corinthians
Jan 13 '06 #5

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

Similar topics

2
by: Kobi Lurie | last post by:
Hello all, I'm trying to make a simple script beginner level script, with just functions. it uses the functions: file_get_contents substr taking into an array the text substr took then...
6
by: Zhang Weiwu | last post by:
Hello. I am working with a php software project, in it (www.egroupware.org) Chinese simplified locate is "zh" while Traditional Chinese "tw". I wish to send correct language attribute in http...
1
by: Chief | last post by:
I am unable to load an xml document that contains Chinese characters in an attribute value. I need to load the document into and XmlDocument object and am using the XmlDocument.Load(string...
8
by: pabv | last post by:
Hello all, I am having a few issues with encoding to chinese characters and perhaps someone might be able to assist. At the moment I am only able to see chinese characters when displayed as...
4
by: K | last post by:
I've an XML file in UTF-8. It contains some chinese characters ( both simplified chinese and traditional chinese). In loading the XML file with MSXML parser, I used the below code to retrieve...
19
by: many_years_after | last post by:
Hi,everyone: Have you any ideas? Say whatever you know about this. thanks.
2
by: Taras_96 | last post by:
Hi everyone, Firstly, I would like to know if you can open chinese filenames under win2000 using PHP 5.0? I have a file named 中国.php, and try to open it using fopen(‘中国.php','r');....
0
by: ouyang | last post by:
Hi everyone, As indicated in the following python script, the dictionary b has Chinese characters: "¤¤¤å". But a.get() returns the dictionary witha little bit different format for the "¤¤¤å¡§: ...
0
by: Jean-Paul Calderone | last post by:
On Sat, 25 Oct 2008 08:36:22 -0700 (PDT), ouyang <zxo102@gmail.comwrote: Try printing b before you put it into the Queue. The Queue isn't doing anything to the objects you pass through it,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.