【代码】Python3检测文件采用的字符编码

前言

Python3检测文件采用的字符编码

源代码

1
2
3
4
5
6
7
import chardet

with open('filename.txt', 'rb') as f:
raw_data = f.read()
result = chardet.detect(raw_data)
encoding = result['encoding']
print(encoding)

完成