By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,235 Members | 1,011 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,235 IT Pros & Developers. It's quick & easy.

how to print unicode structures?

P: n/a
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
Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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''])

[u'\u0430\u0431\u0432']

Serge.
Jul 18 '05 #2

P: n/a
Serge Orlov wrote:
print unicode([u''])

[u'\u0430\u0431\u0432']

Oops, Outlook Express has screwed the encoding, one more evidence that printing unicode is hard :)
I hope this time, the message will be with real Russian characters instead of Latin ones.

Serge.
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.