473,657 Members | 2,763 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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\x fa\xb6\xfe', '\xd6\xd0\xb9\x fa\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 2058
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\x fa\xb6\xfe', '\xd6\xd0\xb9\x fa\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\x fa\xb6\xfe', '\xd6\xd0\xb9\x fa\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.w eb.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.St ringType):
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.washingt on.edu
Jan 3 '06 #4
On 1 Jan 2006 07:35:31 -0800, rumours say that "zxo102" <zx****@gmail.c om>
might have written:
dict.values()

['\xd6\xd0\xb9\x fa\xb6\xfe', '\xd6\xd0\xb9\x fa\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
3121
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 array_count_values
6
22251
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 header, I found "zh" is not standard. I found this line in apache2's default httpd.conf # Simplified Chinese (zh-CN) AddLanguage zh-CN .zh-cn
1
3541
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 filename) method. I get an error that says the document contains invalid characters. The document loads fine with Chinese characters in a node value, but not in an attribute value. I have tried setting the encoding to UTF-8 and UTF-16, but neither solve...
8
11959
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 part of a datagrid. When an input textbox is displayed it does not display chinese characters, but rather the unicode characters stored in the mssql 2000 server backend.
4
6896
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 the data in a node. The CString was then display in CListCtrl. For the traditional chinese characters, they were shown correctly, but for simplified characters, I encounted many "?", but some characters were correct.
19
32794
by: many_years_after | last post by:
Hi,everyone: Have you any ideas? Say whatever you know about this. thanks.
2
5379
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');. I save the source file as UTF-8. I get the error: Warning: fopen(中国.php) : failed to open stream: No such file or directory in E:\Translation\Website
0
978
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 "¤¤¤å¡§: '\xd6\xd0\xce\xc4' . How can I get the dictionary through the Queue as is? {'a': '\xd6\xd0\xce\xc4', 'c': 'abc', 'b': 1232} Cheers.
0
1136
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, you're just surprised at how repr() is presenting the un-altered data. Jean-Paul
0
8306
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
8825
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
8503
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
8605
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...
1
6164
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
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
4152
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...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.