Get a list of all the encodings Python can encode to

后端 未结 9 1294
暗喜
暗喜 2020-11-28 03:19

I am writing a script that will try encoding bytes into many different encodings in Python 2.6. Is there some way to get a list of available encodings that I can iterate ove

9条回答
  •  忘掉有多难
    2020-11-28 03:54

    Maybe you should try using the Universal Encoding Detector (chardet) library instead of implementing it yourself.

    >>> import chardet
    >>> s = '\xe2\x98\x83' # ☃
    >>> chardet.detect(s)
    {'confidence': 0.505, 'encoding': 'utf-8'}
    

提交回复
热议问题