python - 在 python 上使用希伯来语

标签 python eclipse encoding right-to-left hebrew

我在打印希伯来语单词时遇到问题。我正在使用计数器模块,以便 计算给定文本(希伯来语)中的单词数。计数器确实很重要 单词,并识别语言,因为我使用的是 # -*- coding: utf-8 -*-

问题是,当我打印我的计数器时,我得到了奇怪的符号。 (我正在使用 eclipse ) 这是代码和打印品:

# -*- coding: utf-8 -*-
import string
from collections import Counter
class classifier:
def __init__(self,filename):
    self.myFile = open(filename)
    self.cnt = Counter()

def generateList(self):
    exclude = set(string.punctuation)
    for lines in self.myFile:
        for word in lines.split():
            if word not in exclude:
                nWord = ""
                for letter in word:
                    if letter in exclude:
                        letter = ""
                        nWord += letter
                    else:
                        nWord += letter
                self.cnt[nWord]+=1
    print self.cnt

打印:

Counter({'\xd7\x97\xd7\x94': 465, '\xd7\x96\xd7\x95': 432, '\xd7\xa1\xd7\x92\xd7\x95\xd7\xa8': 421, '\xd7\x94\xd7\x92\xd7\x91': 413})

关于如何以正确的方式打印单词有什么想法吗?

最佳答案

您得到的“怪异符号”是 python 表示 unicode 字符串的方式。

你需要对它们进行解码,例如:

>>>打印'\xd7\x97\xd7\x94'.decode('UTF8')
啊啊啊

关于python - 在 python 上使用希伯来语,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18079690/

相关文章:

python - 如何将文本文件制作成数组列表(数组中的数组)并删除空格/换行符

python - 将字符串转换成字典

python - Mako 模板变量名称

java - 如何在java项目中找到哪个数据类没有覆盖toString()方法

python - Werkzeug 引发 BrokenFilesystemWarning

python - 访问 numpy 数组的一部分

eclipse :Apache tomcat

java - 如何删除 Eclipse 中的默认检查样式?

encoding - 这个变长整数编​​码是什么?

ruby - 当编码全部被破坏时,如何使用 Ruby 替换 VC++ 资源文件中的文本?