【发布时间】:2016-12-12 13:14:20
【问题描述】:
我有一个文本数据集,其中存在一些编码问题。 作者指示这样做:
for line in fpointer:
line.encode('latin-1').decode('utf-8')
解决问题。
我想看看为什么需要它,我在修复之前打开了文件并看到了这一行:
103 But in Imax 3-D , the clichés disappear into the vertiginous perspectives opened up by the photography .
转换后变成:
103 But in Imax 3-D , the clichés disappear into the vertiginous perspectives opened up by the photography .
有道理。
但我不明白是什么导致了最初的问题以及修复是如何工作的?
我参考了 unicode python 链接:https://docs.python.org/3/howto/unicode.html
我还检查了字符及其值:
é 的 utf-8 编码是 c3a9,Ã 的 iso-8859-1 编码是 c3,© 是 a9。
这有点道理,但我无法建立联系。
原文件中的行到底是怎么存储的,sn-p代码是怎么修复的?
【问题讨论】:
-
你用的是什么版本的Python(Python2或Python3),原文件是如何打开的?
-
@SergeBallesta 我使用的是python 3,原始文件以读取模式打开,没有指定编码。
标签: python unicode python-unicode