您的位置:首页 > 编程语言 > Python开发

detect the encoding of files in Python

2016-06-23 23:46 309 查看
I found a very useful Python package for detecting the encoding of files. It's chardet. 

1. install chardet

pip install chardet

2. an example of how to use it
Python 2

import urllib
rawdata = urllib.urlopen("http://www.baidu.com").read()
import chardet
chardet.detect(rawdata)

Python 3

from urllib.request import urlopen
rawdata = urlopen("http://www.baidu.com").read()
import chardet
print (chardet.detect(rawdata))

3. results

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息