该问题需要转化原因:
编码格式不同,提示当前是utf-8编码的字符串
解决方式
我使用的是暴力替换的方式
def covert():
File = 'covert.txt'
for line in fileinput.input(File, inplace=1):
line = line.replace('\'', '\"')
line=line.replace('u','')
print line
比较科学的方式:按照相应的编码格式解编码,utf8string ==unicodestring.encode("utf-8")即可。
常见的四种编码格式解编,和编码方式与python字符串之间的转换方式如下:
unicodestring = u"Hello world"
# 将Unicode转化为普通Python字符串:"encode"
utf8string = unicodestring.encode("utf-8")
asciistring = unicodestring.encode("ascii")
isostring = unicodestring.encode("ISO-8859-1")
utf16string = unicodestring.encode("[utf-16](https://www.baidu.com/s?wd=utf-16&tn=SE_PcZhidaonwhc_ngpagmjz&rsv_dl=gh_pc_zhidao)")
编码为相应的形式:
# 将普通Python字符串转化为Unicode:"decode"
plainstring1 = unicode(utf8string, "utf-8")
plainstring2 = unicode(asciistring, "ascii")
plainstring3 = unicode(isostring, "ISO-8859-1")
plainstring4 = unicode(utf16string, "utf-16")