Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

why can't I read this file in python?

lines = [line.rstrip() for line in open(r"C:UsersmagshimimPycharmProjectsasaf_avitalwords.txt")]
for line in lines:
    if len(line) == 9 & line.index(" ") == 3:
        print(line)

I tried to put all lines in the file to a list.

here is the erorr:

Traceback (most recent call last):
  File "C:/Users/magshimim/PycharmProjects/asaf_avital/atav.py", line 2, in <module>
    lines = [line.rstrip() for line in open(r"C:UsersmagshimimPycharmProjectsasaf_avitalwords.txt")]
  File "C:/Users/magshimim/PycharmProjects/asaf_avital/atav.py", line 2, in <listcomp>
    lines = [line.rstrip() for line in open(r"C:UsersmagshimimPycharmProjectsasaf_avitalwords.txt")]
  File "C:Python38libencodingscp1255.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 1: character maps to <undefined>
question from:https://stackoverflow.com/questions/65903517/why-cant-i-read-this-file-in-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...