ํ์ผ์ ์ธ์ฝ๋ฉ์ utf-8๋ก ๋ณํํ๋ ํจ์์ด๋ค.
chardet ํจ์นํค ์ค์น๊ฐ ํ์ํ๋ค
import chardet # ํจํค์ง ์ค์น ํ์
# file_path -> Encoding Type
def is_encoded(file_path: str):
rawdata = open(file_path, mode='rb').read()
data = chardet.detect(rawdata)
result = data['encoding']
return result
# File_path, Encoding_Type -> Change Files encoding type
def to_utf8(file_path: str, encoding_in: str):
try:
with open(file_path, 'r', encoding=encoding_in) as f:
datas = f.read()
with open(file_path, 'w', encoding='utf-8') as k:
k.write(datas)
except:
print('๋ณํ ์คํจ')
# ์๋์ ๊ฐ์ด ํจ์ ํธ์ถํ์ฌ ์ฌ์ฉ
to_utf8(file_path=f'{LOG_PATH}/{LOCAL_SECURITY_POLICY}',
encoding_in=is_encoded(file_path=f'{LOG_PATH}/{LOCAL_SECURITY_POLICY}'))
'๐ํ๋ก๊ทธ๋๋ฐ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ์ด์ฌ] ์์ ์ค์ผ์ค๋ฌ ๋ฑ๋ก ํ์ด์ฌ ์ฝ๋ (0) | 2022.06.29 |
---|---|
[ํ์ด์ฌ] ๋ฐฐํฌ ์๋ํ ์ฐธ๊ณ ์ฝ๋ (0) | 2022.06.29 |
[ํ์ด์ฌ] ๊ตฌ๊ธ ํฌ๋กค๋ง ์ UserAgent ๋ฐ Coockie ์ค์ ํ์ (0) | 2022.06.10 |
[ํ์ด์ฌ] ๊ฐ์ด๋๋ถ (0) | 2022.06.09 |
[ํ์ด์ฌ] pyinstaller๋ก ์๋์ฐ ๋ฆฌ๋ ์ค ์คํํ์ผ ๋ง๋ค๊ธฐ (0) | 2022.06.08 |