chardet of example in python to determine file encoding

  • 2020-06-19 10:42:26
  • OfStack

1. As measured, this version is normally used in 32-bit window7 and python3.2 environments.

2. Usage: Copy the extracted chardet and docs folders to the Lib\ site-ES10en directory in the python3.2 directory.

3. The reference code to determine the file encoding is as follows:


file = open(fileName, "rb")# Want to have "rb" If you don't have this, use it by default gbk Read the file.      
buf = file.read() 
result = chardet.detect(buf) 
file = open(fileName,"r",encoding=result["encoding"]) 
content = file.readlines()

Related articles: