how to print unicode structures?
Serge.Orlov at gmail.com
Mon Jan 17 09:56:59 CET 2005
Timothy Babytch wrote:
> Imagine you have some list that looks like
> ('unicode', 'not-acii', 'russian') and contains characters not from
> acsii. or list of dicts, or dict of dicts.
> how can I print it? not on by one, with "for" - but with just a simple
> print? My debugging would be MUCH simpler.
I think the best (in terms of time) way to do it is to copy pprint.py
to upprint.py and hack it.
> Now when I try print or pprint that variable I get a page full of
> '\xe4\xeb\xa2\xa0\xe6\xe3\xaa\xe6\xe3\xaa' and so on.
It looks like bytes, you should get rid of them as soon as possible. If you're not looking for speed hacks, as a rule of thumb you
should convert bytes to unicode characters as soon as possible. When I try to print Russian characters I get unicode escapes (\u)
not byte escapes (\x) like you:
>>> print unicode([u'ÁÂ×'])
More information about the Python-list