how to show Chinese Characters in the value set of a dictionary
Donn Cave
donn at u.washington.edu
Tue Jan 3 12:45:41 EST 2006
In article <41qd6fF1ftqbvU1 at uni-berlin.de>,
"Diez B. Roggisch" <deets at 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, donn at u.washington.edu
More information about the Python-list
mailing list