python chardet


Author: yifei / Created: June 2, 2017, 2:23 p.m. / Modified: June 2, 2017, 2:29 p.m. / Edit

chardet is used to detect charset from bytes.

usage

In [1]: import cchardet as chardet

In [2]: chinese_bytes = '中文'.encode('utf-8')

In [3]: chardet.detect(chinese_bytes)
Out[3]: {'confidence': 0.7524999976158142, 'encoding': 'UTF-8'}

评论区