0

I am on Mac OS terminal console running Python 2.7

>>> print 'One' # Nice
One
>>> print 'Один' # Unicode strings prints just fine also
Один
>>> print ['One', 'Two'] # List of ascii strings prints just fine
['One', 'Two']
>>> print ['Один', 'Два'] # List of unicode strings prints with codes
['\xd0\x9e\xd0\xb4\xd0\xb8\xd0\xbd', '\xd0\x94\xd0\xb2\xd0\xb0']

How can I avoid getting unicode escape sequences and just get following as an output for the last command?

>>> print ['One', 'Two'] # How can I get this??
[u'Один', u'Два']

I know, I can run a cycle through the list, but in reality my structure is much more complex, so I need a lean command to print the entire structure without encoding letters.

I need this for debugging of complicated data structures. When strings are in escape codes - they are totally unreadable. Is there any library/function which is capable to print without encoding. My console seems to be able to display such characters just fine.

4
  • 1
    You don't have Unicode. You have UTF-8 bytes. You cannot get what you want even when you decode those values from UTF-8 because lists like all containers show representations, not the values directly. Commented Mar 8, 2015 at 13:16
  • This question might have some helpful ideas, since it also deals with Unicode strings inside lists (thus, with the added twist of repr()). Note that explanation of the accepted answer is severely lacking -- you should review the explanation and references in the previous question. Commented Mar 8, 2015 at 13:39
  • I have seen both questions befre I asked this one. I do not see what I want there... Commented Mar 8, 2015 at 15:44
  • It talks about the same subject, but did not provide the answer. So I would appreciate if you either answer my question directly, or unmark this question as duplicate and let others help me. Thanks. Commented Mar 8, 2015 at 16:51

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.