Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 \xc3\x83\xc2\xa9vad\xc3\x83\xc2\xa9s

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?

like image 832
Guhogu Avatar asked Jun 09 '15 18:06

Guhogu


1 Answers

And if you want a Python 3 solution:

b = b'Les \xc3\x83\xc2\xa9vad\xc3\x83\xc2\xa9s'
u = b.decode('utf-8').encode('latin-1').decode('utf-8')
print(u)
# Les évadés
like image 54
James Pringle Avatar answered Oct 03 '22 22:10

James Pringle