with open(txt_file, 'r', encoding='utf-8') as f:
text = f.readline()[:-1]
text = re.sub(pattern, ' ', text).strip()
text = re.sub(r'\s+', ' ', text)
result.append(text)
이런식으로 텍스트 파일을 열고 읽을려고 하는데 오류가 발생했다.
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb1 in position 3: invalid start byte
utf-8
이 아닌 euc-kr
로 해보기with open(txt_file, 'r', encoding='euc-kr') as f:
text = f.readline()[:-1]
text = re.sub(pattern, ' ', text).strip()
text = re.sub(r'\s+', ' ', text)
result.append(text)
utf-8
로 변경하기redutf8
이라고 검색하면 프로그램을 다운로드 할 수 있다.