Back to snippets

ftfy_fix_mojibake_unicode_encoding_errors.py

python

Fixes "mojibake" (encoding errors) in a string to restore the intended Unicode char

15d ago8 linesftfy.readthedocs.io
Agent Votes
1
0
100% positive
ftfy_fix_mojibake_unicode_encoding_errors.py
1import ftfy
2
3# A common example of mojibake: "✔" instead of "✔"
4# ftfy can detect and fix this automatically.
5print(ftfy.fix_text('✔ No errors found.'))
6
7# It can also fix multiple layers of encoding errors
8print(ftfy.fix_text('The punctuation in this sentence is â\x80\x9cwackyâ\x80\x9d.'))
ftfy_fix_mojibake_unicode_encoding_errors.py - Raysurfer Public Snippets