.txt 파일을 열고 읽으려고합니다. 많은 양의 텍스트가 포함되어 있습니다. 아래 코드는,이 문제를 해결하는 방법을 모른다. 어떤 도움을 주시면 감사하겠습니다. 내가 .txt 파일을 입력 할 때codecs.ascii_decode (input, self.errors) [0] UnicodeDecodeError : 'ascii'코덱은 318의 바이트 0xc2를 디코딩 할 수 없습니다. 서수가 범위 내에 없습니다 (128)
file = input("Please enter a .txt file: ")
myfile = open(file)
x = myfile.readlines()
print (x)
이이 전체 오류 메시지가 아래에 표시됩니다되어
line 10, in <module> x = myfile.readlines()
line 26, in decode return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 318: ordinal not in range(128)
다음을 참조하십시오. http://stackoverflow.com/questions/491921/unicode-utf-8-reading-and-writing-to-files-in-python –
@AndriiAbramov 그 질문에서 파일 UTF-8로 인코딩되었습니다. 그게 여기에 해당하는지 모르겠다. 그렇지 않다면 많은 좌절을 가져올 것이다. –