From 3c98da9f9bffa21e14a8adb375d49e8037d112b4 Mon Sep 17 00:00:00 2001 From: dtlnor Date: Fri, 17 Mar 2023 00:03:52 +0900 Subject: [PATCH] export txt without BOM --- REMSGUtil.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/REMSGUtil.py b/REMSGUtil.py index a5eb462..2a2e078 100644 --- a/REMSGUtil.py +++ b/REMSGUtil.py @@ -67,8 +67,10 @@ def getEncoding(filename: str, bufferSize: int = 256*1024) -> str: result = chardet.detect(rawdata) encode = result['encoding'] confidence = result['confidence'] - if encode is None or "ascii" == encode.lower() or (confidence < 0.9 and 'utf' not in encode.lower()): + if encode is None or "ascii" == encode.lower() or (confidence < 0.75 and 'utf' not in encode.lower()): encode = 'utf-8' + if encode.lower() == 'utf-8': + encode = 'utf-8-sig' return encode @@ -222,7 +224,7 @@ def importCSV(msgObj: MSG, filename: str, version: int = None, langCount: int = def exportTXT(msg: MSG, filename: str, lang: int): """write txt file from MSG object with specified language""" - with io.open(filename, "w", encoding="utf-8-sig") as txtf: + with io.open(filename, "w", encoding="utf-8") as txtf: txtf.writelines([''+entry.langs[lang].replace('\r\n','')+'\n' for entry in msg.entrys])