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

Python Method to View File Encoding Format

When reading Chinese, encoding issues often occur, but first you need to understand what the current encoding method is, and then use decode or encode to encode and decode. The following is to view the encoding method using the chardet library.

import chardet
path = "E:\/t.csv"
#path = "E:\/t.zip"
f = open(path,'rb')
data = f.read()
print(chardet.detect(data))

The print result is as follows:

{"encoding": "GB2312', 'confidence': 0.99, 'language': 'Chinese'}

This is the full content of the method of checking the encoding format of Python files shared by the editor. I hope it can provide a reference for everyone, and I also hope everyone will support the Yell Tutorial.

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

You May Also Like