|
import chardet
|
|
|
|
|
|
def read_encoding(path):
|
|
import chardet
|
|
return chardet.detect(open(path, 'rb').read(4096))['encoding']
|
|
|
|
|
|
def open_auto(*args, **kwargs):
|
|
try:
|
|
file = args[0]
|
|
except Exception:
|
|
file = kwargs['file']
|
|
return open(*args, **kwargs, encoding=read_encoding(file))
|