Pyenchant弄乱了外国字符,拼写检查失败。我的女朋友是德语,所以“hßlich”这个词是一个真正的德语单词,我也使用不同的拼写检查服务来检查这个词。在
脚本文件编码是ANSI as UTF-8。我也尝试过把这个词编码和解码成不同的字符编码。在
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Python bindings for the enchant spellcheck
import enchant
# Enchant dictionary
enchantdict = enchant.Dict("de_DE")
# Define german word for "ugly"
word = "häßlich"
# Print the original word and the spellchecked version of it
print word, "=", enchantdict.check(word)
输出如下: h├├├ƒlich=错误
另外,如果我将脚本编码改为纯ANSI,我得到的结果是:
^{pr2}$hõ¯lich = ** (python.exe:1096): CRITICAL **: enchant_dict_check: assertion `g_utf8_validate(word, len, NULL)' failed
我正在使用: pyenchant-1.6.5.win32.exe python-2.7.3.msi Windows 7系统
请告诉我一个更好的拼写检查方法:)
在Python中有两种类型的字符串:字节字符串和Unicode字符串您需要在字符串前面加一个“u”才能使其成为Unicode字符串:
还有häßlich is the old spelling of hässlich(后者在字典中,将作为建议返回)。如果你想让拼写正确的话,你可以把hßlich添加到你个人的拼写正确的单词列表中。在
在附魔。添加(文字)
相关问题 更多 >
编程相关推荐