更新文本编码错误
This commit is contained in:
parent
249bfbcb9f
commit
54751fe89e
@ -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()
|
||||
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()
|
||||
Loading…
x
Reference in New Issue
Block a user