Python 3.4 decode bytes
I am trying to write a file in python, and I can't find a way to decode a byte object before writing the file, basically, I am trying to decode this bytes string:
Les xc3x83xc2xa9vadxc3x83xc2xa9s
into this, which is the original text I'm trying to recover:
Les évadés
I tried using the .decode('utf-8') and encode('utf-8') but nothing seems to work...
I always get Les évadés
as a result... I am using python 3.4.3
Anyone can help?
如果你想要一个Python 3解决方案:
b = b'Les xc3x83xc2xa9vadxc3x83xc2xa9s'
u = b.decode('utf-8').encode('latin-1').decode('utf-8')
print(u)
# Les évadés
What you need to do is to decode and then encode:
s = "Les xc3x83xc2xa9vadxc3x83xc2xa9s"
utf = s.decode('utf-8')
latin = utf.encode("latin-1","ignore")
print latin
--> Les évadés
链接地址: http://www.djcxy.com/p/27024.html上一篇: 在没有Apple Developer Program的情况下在iOS上安装应用程序(Xcode 7)
下一篇: Python 3.4解码字节