python2--编码问题汇总
# unicode编码字符串转码utf8 aaa = "\xxx\xxx\xxx\xxx" print(aaa.encode('utf-8').decode('unicode_escape'))
# 字典类型的unicode编码类型,转utf8 # 1、可以用json.loads() # 2、 from ast import literal_eval res = literal_eval(str(字典).replace('u\'', '\'').decode("unicode-escape")) print(res)
# python2中列表里的u 方法一: all_symptom = [u'abcde'] str_symptom = str(all_symptom).replace('u\'','\'') print str_symptom.decode("unicode-escape") 方法二: from ast import literal_eval all_symptom = [u'abcde'] str_symptom = str(all_symptom).replace('u\'','\'') print str_symptom print type(str_symptom) print literal_eval(str_symptom) print type(literal_eval(str_symptom))
python 中文名:蟒蛇,设计者:Guido van Rossum