Python
import chardet
def detect_encoding(text):
result = chardet.detect(text)
encoding = result['encoding']
confidence = result['confidence']
return encoding, confidence
if __name__ == '__main__':
encoding, confidence = detect_encoding(text)
print(f"Detected encoding: {encoding}")
print(f"Confidence: {confidence}")
Shell
Detected encoding: UTF-8
Confidence: 0.87625