K
kj
Is there a simple way to get Python to pretty-print a dict whose
values contain Unicode? (Of course, the goal here is that these
printed values are human-readable.)
If I run the following simple script:
from pprint import pprint
x = u'\u6c17\u304c\u9055\u3046'
print '{%s: %s}' % (u'x', x)
print {u'x': x}
pprint({u'x': x})
The first print statement produces perfectly readable Japanese,
but the remaining statements both produce the line
{u'x': u'\u6c17\u304c\u9055\u3046'}
I've tried everything I can think of (including a lot of crazy
stuff) short of re-writing pprint from scratch (which I think would
be faster than grokking it and hacking at it).
Isn't there an easier way to do this?
Thanks!
~K
values contain Unicode? (Of course, the goal here is that these
printed values are human-readable.)
If I run the following simple script:
from pprint import pprint
x = u'\u6c17\u304c\u9055\u3046'
print '{%s: %s}' % (u'x', x)
print {u'x': x}
pprint({u'x': x})
The first print statement produces perfectly readable Japanese,
but the remaining statements both produce the line
{u'x': u'\u6c17\u304c\u9055\u3046'}
I've tried everything I can think of (including a lot of crazy
stuff) short of re-writing pprint from scratch (which I think would
be faster than grokking it and hacking at it).
Isn't there an easier way to do this?
Thanks!
~K