pip install chardet 安装chardet显示当前文件编码信息
# -*- coding: UTF-8 -*-
import os
import chardet
file_dir = 'D:\dataexch\exp_Rtdb_Tag' #文件路径
file_type = '.cpp .h .xml' #文件类型
file_encoding = 'GBK' #编码类型
def transcoding(type_list):for root, dirs, files in os.walk(file_dir, topdown=False):
for i in files:
files_name = os.path.join(root, i)
for type in type_list:
if type == os.path.splitext(files_name)[1]: #筛选文件格式
print(files_name)
f = open(files_name,'rb')
data = f.read()