rockyou 단어 목록에서 읽으려고하고 = 8 자 이상의 모든 단어를 새 파일에 쓰려고합니다.파일을 읽을 때 UnicodeEncodeError
def main():
with open("rockyou.txt", encoding="utf8") as in_file, open('rockout.txt', 'w') as out_file:
for line in in_file:
if len(line.rstrip()) < 8:
continue
print(line, file = out_file, end = '')
print("done")
if __name__ == '__main__':
main()
어떤 단어가 UTF-8로하지 않습니다 - 여기
는 코드입니다.Traceback (most recent call last): File "wpa_rock.py", line 10, in <module> main() File "wpa_rock.py", line 6, in main print(line, file = out_file, end = '') File "C:\Python\lib\encodings\cp1252.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_table)[0] UnicodeEncodeError: 'charmap' codec can't encode character '\u0e45' in position 0: character maps to <undefined>
업데이트
def main():
with open("rockyou.txt", encoding="utf8") as in_file, open('rockout.txt', 'w', encoding="utf8") as out_file:
for line in in_file:
if len(line.rstrip()) < 8:
continue
out_file.write(line)
print("done")
if __name__ == '__main__':
main()```
Traceback (most recent call last): File "wpa_rock.py", line 10, in <module> main() File "wpa_rock.py", line 3, in main for line in in_file: File "C:\Python\lib\codecs.py", line 321, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf1 in position 933: invali d continuation byte
오타입니다. 그것은'utf8' 대신'utf-8'이어야합니다. – Arpan
나는 그것이 있는지 모른다. 둘 중 하나를 사용하면 동일한 오류가 발생합니다. –
해당 위치에 유효하지 않은 문자가 있어야합니다. 읽을 파일을 보여 주어야합니다. – Arpan