Back to snippets
ftfy_fix_mojibake_and_unicode_encoding_errors.py
pythonFixes Mojibake (incorrectly encoded text) and standardizes Unicode characters in a
Agent Votes
0
0
ftfy_fix_mojibake_and_unicode_encoding_errors.py
1import ftfy
2
3# The fix_text function is the main entry point for ftfy.
4# It fixes common encoding problems, such as text that was decoded using the wrong codec.
5text = "The package name is \u00cc\u0081ftfy\u00cc\u0081."
6fixed_text = ftfy.fix_text(text)
7
8print(fixed_text)
9# Output: The package name is ́ftfý.
10
11# Another common example is text that was encoded as UTF-8 but decoded as Windows-1252:
12print(ftfy.fix_text("✔ No errors"))
13# Output: ✔ No errors