Skip to content

Instantly share code, notes, and snippets.

@x
Created April 1, 2021 22:28
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 x/0155bb6bc0dcdaafccdf259b9c2805c1 to your computer and use it in GitHub Desktop.
Save x/0155bb6bc0dcdaafccdf259b9c2805c1 to your computer and use it in GitHub Desktop.
Decode anything probably
In [1]: import chardet
In [2]: s = b'200 \xb5l Ultra Po'
In [3]: chardet.detect(s)
Out[3]: {'encoding': 'ISO-8859-1', 'confidence': 0.73, 'language': ''}
In [4]: s.decode(chardet.detect(s)['encoding'])
Out[4]: '200 µl Ultra Po'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment