【发布时间】:2015-11-18 19:01:25
【问题描述】:
我正在使用 Python 的 NLTK TaggedCorpusReader 创建文本文件的语料库。但是,其中一个文件不是 utf-8 格式或具有不受支持的字符。有没有办法告诉哪个文件包含问题?
这是我的代码:
import nltk
corpus=nltk.corpus.TaggedCorpusReader("filepath", '.*.txt', encoding='utf-8') #I added the encoding when I saw some answer about that, but it doesn't seem to help
words=corpus.words()
for w in words:
print(w)
我的错误:
UnicodeDecodeError:“utf-8”编解码器无法解码位置 0 中的字节 0xa0:无效的起始字节
【问题讨论】:
-
你能把你的输入文件贴在某个地方吗,我们可以帮你检查它是否是编码问题。你也在 python3 上吗?
-
@alvas 我做了更多的挖掘,问题是文件没有以 utf-8 编码。我正在使用 Python 3。