How do I get Python Interactive Shell to print Cyrillic characters?
I am using Pymorphy2 in my project as a cyrillic morphological analyzer. But when I try to print the word list I get this:
>>> for t in terms:
... p = morph.parse(t)
... if 'VERB' in p[0].tag:
... t = p[0].normal_form
... elif 'NOUN' in p[0].tag:
... t = p[0].lexeme[0][0]
...
>>> terms
[u'\u041f\u0430\u0432\u0435\u043b', u'\u0445\u043e\u0434\u0438\u0442', u'\u0434\u043e\u043c\u043e\u0439']
How to make it possible to print Russian characters in the python shell?
+3
source to share
1 answer
You see the repr representation of unicode strings if you iterate over the list or index and print every string you see you want.
In [4]: terms
Out[4]:
[u'\u041f\u0430\u0432\u0435\u043b',
u'\u0445\u043e\u0434\u0438\u0442',
u'\u0434\u043e\u043c\u043e\u0439'] # repr
In [5]: print terms[0] # str
In [6]: print terms[1]
If you want them all to be printed and look like a list, use str.format and str.join:
terms = [u'\u041f\u0430\u0432\u0435\u043b',
u'\u0445\u043e\u0434\u0438\u0442',
u'\u0434\u043e\u043c\u043e\u0439']
print(u"[{}]".format(",".join(terms)))
Output:
[,,]
+4
source to share