Python: How to Encode the File (including HTML, TXT, Doc, etc.)

Python gets file encoding (including HTML TXT Doc, etc.)

import chardet
def get_file_encoding(file_path):
    f3 = open(file_path, mode='rb')  # Read files in binary mode
    data = f3.read() # Get file contents
    f3.close() # Close the file.

    result = chardet.detect(data) # Detect file contents
    return result.get("encoding")

Read More: