如何在输出中获得西里尔字母,Python? [英] How do I get Cyrillic in the output, Python?
本文介绍了如何在输出中获得西里尔字母,Python?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取西里尔字母而不是u'...
how do I get Cyrillic instead of u'...
代码是这样
def openfile(filename):
with codecs.open(filename, encoding="utf-8") as F:
raw = F.read()
do stuff...
print some_text
打印
>>>[u'.', u',', u':', u'\u0432', u'<', u'>', u'(', u')', u'\u0437', u'\u0456']
推荐答案
看起来some_text
是unicode对象的列表.当您打印这样的列表时,它将打印列表中元素的reprs
.因此,请尝试:
It looks like some_text
is a list of unicode objects. When you print such a list, it prints the reprs
of the elements inside the list. So instead try:
print(u''.join(some_text))
join 方法将some_text
的元素与元素之间的空白空间u''
.结果是一个unicode对象.
The join method concatenates the elements of some_text
, with an empty space, u''
, in between the elements. The result is one unicode object.
这篇关于如何在输出中获得西里尔字母,Python?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文