English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Python-Dateikodierung erkennen mit chardet (Beispiel dargestellt)

1实测,这个版本在32for windows7and python3.2environment and use them normally. 

2Usage: Copy the chardet and docs folders after unzipping to the python3.2The Lib\site directory-The packages directory can be used normally. 

3The reference code for judgment of file encoding is as follows:

file = open(fileName, "rb")#"rb" must be used, otherwise the default gbk encoding will be used to read the file.     
buf = file.read() 
result = chardet.detect(buf) 
file = open(fileName,"r",encoding=result["encoding"]) 
content = file.readlines()

This is the full content of the tutorial on file encoding judgment in Python (chardet example explanation) shared by the editor. I hope it can provide a reference for everyone and I hope everyone will support the Yelling Tutorial more.

Declaration: The content of this article is from the Internet, owned by the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#w3Please replace # with @ when sending an email to report violations, and provide relevant evidence. Once verified, this site will immediately delete the infringing content.

Mag dir gefallen