how to print unicode structures?

T

Timothy Babytch

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.

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.

I use Python 2.4, Fedora Linux, UTF-8 locale
 
S

Serge Orlov

Timothy said:
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:
[u'\u0430\u0431\u0432']

Serge.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,470
Messages
2,571,809
Members
48,797
Latest member
PeterSimpson
Top