如何让Python交互式Shell打印西里尔文符号?

2024-06-11 07:12:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我在我的项目中使用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']

如何在pythonshell中打印俄语字符?在


Tags: 项目in分析器列表forifparsetag
1条回答
网友
1楼 · 发布于 2024-06-11 07:12:09

您看到的是unicode字符串的repr表示,如果您循环查看列表或索引并打印每个字符串,您将看到所需的输出。在

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.格式以及结构连接公司名称:

^{pr2}$

输出:

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

相关问题 更多 >