python----字符串,反向编码与乱码记录
字符串反编译
百思不得其解,搜了很多资料,耗费了很长时间,弄出来了
1.今天遇到一道题:把下边字典里值用中文显示出来
{'word': '\\xE5\\x95\\x8A\\xE5\\x95\\x8A\\xE5\\x95\\x8A\\xE5\\x95\\x8A\\xE5\\x95\\x8A\\xE5\\x95\\x8A'}
# data = {'word': '\\xE5\\x95\\x8A\\xE5\\x95\\x8A\\xE5\\x95\\x8A\\xE5\\x95\\x8A\\xE5\\x95\\x8A\\xE5\\x95\\x8A'} # new_data = data['word'] # print(new_data.encode().decode('unicode-escape').encode('latin1').decode('utf-8'))
2.上边的弄出来了, '\xE7\xAD\x89\xE4\xBD\xA0\xE5\x8C\x85\xE5\x85\xBB\xE6\x88\x91' 用上边的方法是否能弄出来呢?
a = '\xE7\xAD\x89\xE4\xBD\xA0\xE5\x8C\x85\xE5\x85\xBB\xE6\x88\x91' print(a.encode().decode('unicode-escape').encode('latin1').decode('utf-8'))
结果:
C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\python.exe F:/安装包/moduile_three/服务端.py
çä½ å
å
Ⱦ
Process finished with exit code 0
显然是不行的,乱码,又弄了很长时间,经人指点
a = '\xE7\xAD\x89\xE4\xBD\xA0\xE5\x8C\x85\xE5\x85\xBB\xE6\x88\x91' b = a.encode('raw_unicode_escape').decode('utf-8') print(b) 结果: C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\python.exe F:/安装包/moduile_three/服务端.py 等你包养我 Process finished with exit code 0
哇塞!!!还有这操作,突然觉得自己太low了~继续学习....