python 打开文件时编码格式的探测

1. 思路

用二进制打开文件,用chardet模块探测编码

2. 实现

import chardet
wiht open('filename','rb') as f:
    data=f.read()
print(chardet.detect(data))
Table of Contents