From 54751fe89ebb5202054589cc78ef8e80c8f1f3f0 Mon Sep 17 00:00:00 2001 From: 997146918 <997146918@qq.com> Date: Fri, 8 Aug 2025 19:41:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=96=87=E6=9C=AC=E7=BC=96?= =?UTF-8?q?=E7=A0=81=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AITrain/utils.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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