Skip to content

Instantly share code, notes, and snippets.

@jpluimers
Created November 7, 2021 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpluimers/adff0ffe6eec6fdc7eab642ffdfd4ee5 to your computer and use it in GitHub Desktop.
Save jpluimers/adff0ffe6eec6fdc7eab642ffdfd4ee5 to your computer and use it in GitHub Desktop.
Example on python.org showing how to use ftfy
Python 3.9.5 (default, May 27 2021, 19:45:35)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.system('sh')
$ pip install ftfy
pDefaulting to user installation because normal site-packages is not writeable
Looking in links: /usr/share/pip-wheels
Collecting ftfy
Downloading ftfy-6.0.3.tar.gz (64 kB)
|████████████████████████████████| 64 kB 4.9 MB/s
Stored in directory: /home/.anon-bca447f2e1574daaaa3f9740/.cache/pip/wheels/3d/ee/4b/03a4e2e591ea56687af
ythoRequirement already satisfied: wcwidth in /usr/local/lib/python3.9/site-packages (from ftfy) (0.2.5)
Building wheels for collected packages: ftfy
n Building wheel for ftfy (setup.py) ... done
Created wheel for ftfy: filename=ftfy-6.0.3-py3-none-any.whl size=41913 sha256=18ce752a33f0abca0c843d5b7157ae9ea4ac56bdef179b5d1b8b79adbf682d0b
Stored in directory: /home/.anon-bca447f2e1574daaaa3f9740/.cache/pip/wheels/3d/ee/4b/03a4e2e591ea56687aff999edc83827a2ace523baab75b8e41
Successfully built ftfy
Installing collected packages: ftfy
Successfully installed ftfy-6.0.3
python
Python 3.9.5 (default, May 27 2021, 19:45:35)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ftfy
>>> ftfy.fix_text("Pyreneeën")
'Pyreneeën'
>>> ftfy.fix_and_explain("Pyreneeën")
ExplainedText(text='Pyreneeën', explanation=[('encode', 'latin-1'), ('decode', 'utf-8'), ('encode', 'latin-1'), ('decode', 'utf-8')])
>>> ftfy.fix_and_explain("Pyreneeën")
ExplainedText(text='Pyreneeën', explanation=[('encode', 'latin-1'), ('decode', 'utf-8')])
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment