''' 检测文件编码格式 ''' import chardet data = open(file_name, 'r').read() print(chardet.detect(data)['encoding'])