import chardet
def get_file_encoding(file):
"""
获取文件编码
:param file:文本路径
:return:文本编码
"""
with open(file, "rb")as fp:
return chardet.detect(fp.read(1024 * 1024))["encoding"]
python 获取文件编码
于 2022-09-02 10:43:18 首次发布