python编码转换

1.unicode转中文

f='\u897f\u5c0f\u6cb3\u7684\u590f\u5929'
print("eval转换数据格式:",eval("\'"+f+"\'"))

输出:

eval转换数据格式: 西小河的夏天

2.字典中有需要转码

a=b'{"from":"en","to":"zh","trans_result":[{"src":"hello","dst":"\\u4f60\\u597d"}]}'
print(eval(a))

输出:

{'from': 'en', 'to': 'zh', 'trans_result': [{'src': 'hello', 'dst': '你好'}]}

 

posted @ 2019-07-29 23:50  做一只热爱生活的小透明  阅读(138)  评论(0)    收藏  举报