FarmerLi
4/13/2018 - 5:31 AM

Python detect file's encoding

Python detect file's encoding

import chardet

def detect_file_encoding(file_path):
    f = open(file_path, 'r')
    data = f.read()
    predict = chardet.detect(data)
    f.close()
    return predict['encoding']