Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python fix french accents parsed as =C3=A9

In python i’m stuck with a couple of strings from french language with accents that I can’t convert back to normal, e.g.:

word1 = 'install=C3=A9' # should be installé
word2 = 'transf=E9r=E9' # should be transféré
word3 = 'bient=C3=B4t'  # should be bientôt

Most documentation I read specify to read the files with some encodings=’utf-8′ or so, but here I’m stuck with actual strings. Is there a way to decode the strings or should I build a maximega .replace() function ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The encoding seems to be Quoted Printable.

import quopri
word1 = 'install=C3=A9'
byteString = quopri.decodestring(word1)
string = byteString.decode('utf-8')
print(string)

Actually the function expects bytes as input, so it would be even better to have the words declared as bytes:

word1 = b'install=C3=A9'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading