如何使Python交互式Shell打印西里尔字母符号?

如何使Python交互式Shell打印西里尔字母符号?,python,shell,unicode,character-encoding,cyrillic,Python,Shell,Unicode,Character Encoding,Cyrillic,我在我的项目中使用Pymorphy2作为西里尔语形态分析器。 但当我试着打印出单词列表时,我得到了以下结果: >>> 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]

我在我的项目中使用Pymorphy2作为西里尔语形态分析器。 但当我试着打印出单词列表时,我得到了以下结果:

>>> 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']
如何在python shell中打印俄语字符?

您看到了unicode字符串的表示形式,如果您在列表或索引上循环并打印每个字符串,您将看到所需的输出

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]
ходит
如果要将它们全部打印出来并使其看起来像列表,请使用str.format和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)))
输出:

[Павел,ходит,домой]

但是,如果我在列表中有1000个元素,并且希望看到整个单词列表打印出来,而不需要对列表进行冗余的迭代,该怎么办呢?当您打印列表时,它无论如何都是迭代的。如果您需要经常打印此类列表,您可以实施
print\u list
function@paus:考虑一下:
print(unicode\u text)
print(repr(unicode\u text))
(或
print(ascii(unicode\u text))
在Python 3上的区别。要打印整个列表,请执行以下操作:
fort-terms:print(t)
print(“\n”.join(terms))
。如果不进行迭代,则无法打印列表。