0.Brief introduction:
It’s hard to detect the type of the string , for example we open a file and want to detect the type of it.
1.Install:
pip install chardet
2.Use chardet:
Input:
import urllib
rawdata = urllib.urlopen(“http://www.baidu.com/“).read()
import chardet
chardet.detect(rawdata)Output:
{‘confidence’: 0.99, ‘encoding’: ‘utf-8’}