0

Is there any way we can find what kind of encoding is used in bytes string with codecs in python. There is a method in chardet chardet.detect(string)['encoding'] Is there any method similar to this in codecs python

1 Answers1

0

There isn't a built-in method, because it wouldn't be possible to reliably determine this for arbitrary values and arbitrary encodings. (For example, any text containing only ASCII characters is valid in most other encodings.)

The best you could do is a series of try-catch blocks where you guess a series of encodings (eg UTF8, UTF16) and go to the next if there is an invalid character.

Christoph Burschka
  • 4,467
  • 3
  • 16
  • 31