[utf-8] 파일을 open해서 replace를 하고 저장(w,a)하면, [ascii] 파일로 인식합니다. ascii로 인식되도록 변경되지않고, utf-8로 인식되게 저장하려면 어떻게하나요. 다국어 번역용 파일이라서, ascii로 인식되면 안됩니다.
encoding='UTF-8-SIG' 로 지정해서 저장하면 다행히 UTF-8-SIG로 인식되게 저장이 되는데, encoding='utf-8'로는 안되네요. (ascii로 인식되게 바뀌어서 저장돼요.)
src1 = "’"
tar1 = "'"
with open(filepath, "r", encoding='utf-8') as file:
content = file.read()
content = content.replace(src1, tar1)
with open(filepath2, "a", encoding='UTF-8') as file:
file.write(content)
codecs.open / io.open 혹시몰라 해봤는데, 동작에는 변화없습니다.