将非 "utf-8" 特征文件中的字符转换为 python 中的英语等值
converting characters from non "utf-8" characterized file to english equivilances in python
我的文件中有这样的行:
M Aad 4 $
M Aadam 1 $
F Aadje 1 $
M Ådne + 1 $
当我运行下面的代码;
#!/usr/bin/python
# -*- coding: utf-8 -*-
import csv, unicodedata, urllib
from unidecode import unidecode
from textblob import TextBlob
with open('names.csv', 'rb') as f:
reader = csv.reader(f)
my_list = list(reader)
for a in range(len(my_list)):
name = my_list[a][0]
name = unicode(name,'ISO-8859-15')
print name
我在某些行上得到这样的输出:
F <Z^>ydr<edeg> 1 $
这个案例Whosebug上有很多类似的问题,但是他们的解决方案不适合我的问题。
我该如何解决这个问题?
听起来你的输入实际上不是UTF-8,它似乎是ISO-8859-*(可能是ISO-8859-15或ISO-8859-1),0xC5是Å的ISO编码( UTF-8 编码为 0xC3 0xA5).
我的文件中有这样的行:
M Aad 4 $
M Aadam 1 $
F Aadje 1 $
M Ådne + 1 $
当我运行下面的代码;
#!/usr/bin/python
# -*- coding: utf-8 -*-
import csv, unicodedata, urllib
from unidecode import unidecode
from textblob import TextBlob
with open('names.csv', 'rb') as f:
reader = csv.reader(f)
my_list = list(reader)
for a in range(len(my_list)):
name = my_list[a][0]
name = unicode(name,'ISO-8859-15')
print name
我在某些行上得到这样的输出:
F <Z^>ydr<edeg> 1 $
这个案例Whosebug上有很多类似的问题,但是他们的解决方案不适合我的问题。
我该如何解决这个问题?
听起来你的输入实际上不是UTF-8,它似乎是ISO-8859-*(可能是ISO-8859-15或ISO-8859-1),0xC5是Å的ISO编码( UTF-8 编码为 0xC3 0xA5).