小陆同学

python 中文名:蟒蛇,设计者:Guido van Rossum

导航

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))

 

posted on 2020-08-28 20:59  小陆同学  阅读(120)  评论(0编辑  收藏  举报