这是一个例子,希望对你有所帮助:
import csv
import chardet
def detect_file_encoding(filepath):
with open(filepath, 'rb') as f:
raw_data = f.read()
result = chardet.detect(raw_data)
return result['encoding']
def convert_to_utf8_csv(filepath):
encoding = detect_file_encoding(filepath)