diff --git a/AITrain/utils.py b/AITrain/utils.py index bb90aa9..b127913 100644 --- a/AITrain/utils.py +++ b/AITrain/utils.py @@ -86,5 +86,12 @@ class ReadFiles: @classmethod def read_text(cls, file_path: str): # 读取文本文件 - with open(file_path, 'r', encoding='utf-8') as file: - return file.read() \ No newline at end of file + encodings = ['gb18030', 'gbk', 'gb2312', 'big5', 'iso-8859-5', 'cp1252', 'latin1'] + for enc in encodings: + try: + with open(file_path, 'r', encoding=enc) as f: + return f.read() + except : + continue + # with open(file_path, 'r', encoding='utf-8') as file: + # return file.read() \ No newline at end of file