파이썬에서 인코딩 에러날때 (ISO-8859-1 -> CP949 변환)


파이썬에서 인코딩 에러날때 (ISO-8859-1 -> CP949 변환)

windows 배치파일에서 생성된 텍스트 파일인데 python에서 불러올때 자꾸 에러가 났따. >>> f = open('A.txt',"r") >>> for i in f: ... print(i) ... Traceback (most recent call last): File "<stdin>", line 1, in <module> UnicodeDecodeError: 'cp949' codec can't decode byte 0xd1 in position 4588: illegal multibyte sequence 그래서 불러올떄 인코딩을 utf-8, euc-kr, ascii 다 바꿔봐도 안됬었다... f = open("a.txt","rt",encoding='utf-8') f = open("a.txt","rt",encoding='euc-kr') f = open("a.txt","rt",encoding='ascii') 결론은 저 텍스트 파일이 어떤 인코딩인지 알고 싶었으나 notepad++에서는 ...


#chardet #print #python #windows1252 #배열에다가 #인코딩에러

원문링크 : 파이썬에서 인코딩 에러날때 (ISO-8859-1 -&gt; CP949 변환)