shell pip install chardet python import chardet with open('text.txt', 'rb') as f: data = f.read() result = chardet.detect(data) print(result['encoding'], result['confidence'])