简体   繁体   中英

Python print unicode strings in arrays as characters, not code points

If I've got a dictionary of the form:

a = {u"foo": u"ბარ"}

and I write

>>> print a[u"foo"]

I get

ბარ

as expected. But if I write

>>> print a

I get

{u'foo': u'\ბ\ა\რ'} , but I would prefer the characters themselves to be printed.

All the data will ultimately get dumped into a database anyway, so it's not critical to solve this problem, but for debugging it would be nice if I could get readable output when I print the entire dictionary. Is there any way to do this?

For those who are curious, the script is Georgian, and yes, it says "bar".

这适用于我的终端:

print repr(a).decode("unicode-escape")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM