【发布时间】:2018-09-06 15:34:27
【问题描述】:
我有一个 tsv 文件,在某些行中,特定列包含混合格式,例如:Hapoel_Be\u0027er_Sheva_A\u002eF\u002eC\u002e,应该是Hapoel_Be'er_Sheva_A.F.C.。
这是我用来读取文件和拆分列的代码:
with open(path, 'rb') as f:
for line in f:
cols = line.decode('utf-8').split('\t')
text = cols[3].decode('unicode-escape') #Here is the column that has the above mentioned mixed format
错误信息:
UnicodeEncodeError: 'ascii' codec can't encode character u'\u0160' in position 6: ordinal not in range(128)
我想知道在读取文件时如何从第一种混合格式转换为另一种?我正在使用 python 2.7。
非常感谢,
【问题讨论】:
-
这是 python 2 还是 3?
-
@FHTMitchell 抱歉忘记指定。这是python 2.7。
标签: python text unicode encoding compiler-errors