f = open("text.txt", "r", encoding="utf-8")
print(f.read())
f.close()
import io
import chardet
import os
import codecs
filename = 'test_file.txt'
bytes = min(32, os.path.getsize(filename))
raw = open(filename, 'rb').read(bytes)
if raw.startswith(codecs.BOM_UTF8):
encoding = 'utf-8-sig'
else:
result = chardet.detect(raw)
encoding = result['encoding']
infile = io.open(filename, 'r', encoding=encoding)
data = infile.read()
infile.close()
print(data)