AutoFramework/Base/Class/Open.py

15 lines
309 B
Python
Raw Normal View History

2022-08-31 03:12:45 +08:00
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))