how to show Chinese Characters in the value set of a dictionary
Diez B. Roggisch
deets at nospam.web.de
Sun Jan 1 11:09:51 EST 2006
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
More information about the Python-list
mailing list