Like in How to print national characters in list representation? , you need to use a custom procedure to print your data that would print strings themselves instead of their repr
:
def nrepr(data):
city_items=[]
for city, jukebox in data.iteritems():
jukebox_items=[]
for song,artist in jukebox.iteritems():
jukebox_items.append(u'"%s":"%s"' % (song,artist) )
city_items.append(u'"%s":{%s}' % (city, u",".join(jukebox_items)))
return u'{%s}' % u",".join(city_items)
>>> data={u'Osaka':{u'\u3086\u3081\u3044\u3089\u3093\u304b\u306d':u'Takajin Yashiki'}}
>>> print nrepr(data)
{"Osaka":{"ゆめいらんかね":"Takajin Yashiki"}}
(use from __future__ import unicode_literals
at the start of the file to avoid putting u
before every literal)
You are not constrained to mimicking Python's default output format, you can print them any way you like.
Alternatively, you can use a unicode
subclass for your strings that would have repr
with national characters:
class nu(unicode):
def __repr__(self):
return self.encode('utf-8') #must return str
>>> data={nu(u'Osaka'):{nu(u'\u3086\u3081\u3044\u3089\u3093\u304b\u306d'):nu(u'Takajin Yashiki')}}
>>> data
{Osaka: {ゆめいらんかね: Takajin Yashiki}}
This is problematic 'cuz repr
output is presumed to only contain ASCII characters and various code relies on this. You are extremily likely to get UnicodeError
s in random places. It will also print mojibake if a specific output channel's encoding is different from utf-8
or if further transcoding is involved.
Hello
{{citiesAndSongs}} then, when running google app engine it opens localhost and outputs the dictionary. However, some city names aren't displayed properly. u'Bras\xedlia' and u'Bogot\xe1' are a couple examples of special character cities that don't output as they should. – Katherine Waller Nov 28 '18 at 23:56