Unicode output on ipython laptop

I need to work with Unicode characters (Cyrillic) in an IPython Notebook. Is there a way to output strings in Unicode and not their unicode or utf8 codes? I would like to have ["",""]as a conclusion in the last two examples below.

In [62]: ""

Out[62]: '\xd0\x90\xd0\x91\xd0\x92'

In [63]: u""

Out[63]: u'\u0410\u0411\u0412'

In [64]: print ""



In [65]: print u""



In [66]: print ["",""]

['\xd0\x90\xd0\x91', '\xd0\x92\xd0\x93']

In [67]: print [u"",u""]

[u'\u0410\u0411', u'\u0412\u0413']
+3
source share
3 answers

You need to switch to Python 3 and get some nice reprUnicode strings.

+3
source

In Python 2 (with or without IPython), you can use a string codec unicode_escapeto simulate the correct Unicode reprs:

In [1]: print repr([u"",u""]).decode('unicode_escape')

[u'', u'']

https://docs.python.org/2/library/codecs.html#python-specific-encodings

Mark Ransom, (, , ). , IPython.

+3

Do not print the entire list; print each item in the list separately. Or convert the list to a string:

print u'[' + u','.join(string_list) + u']'
+1
source

All Articles