반응형

윈도우에서 파일 읽는 코드를 사용시 다음과 같은 에러가 발생할 때가 있습니다.

 

UnicodeDecodeError: 'cp949' codec can't decode byte 0xe2 in position 5302: illegal multibyte sequence

 

with open('test.py', 'r') as f:
    text = f.read()

print(text)

 

 

2023. 3. 28. 최초작성

 

 

 

 

 

이 문제를 해결하려면 encoding='utf-8'를 추가해줘야 합니다. 

 

with open('test.py', 'r', encoding='utf-8') as f:
    text = f.read()

print(text)


반응형

문제 발생시 지나치지 마시고 댓글 남겨주시면 가능한 빨리 답장드립니다.

도움이 되셨다면 토스아이디로 후원해주세요.
https://toss.me/momo2024


제가 쓴 책도 한번 검토해보세요 ^^

+ Recent posts