I'm trying to read the content of a text file, line by line, with this code:
import os.path
file_to_read = open("file_name.txt", "r")
lines = file_to_read.readlines()
When I run it I get the following error:
Traceback (most recent call last):
File "D:/Files/test.py", line 4, in < module>
lines = file_to_read.readlines()
File "C:Program Files (x86)Microsoft Visual StudioSharedPython39_64libencodingscp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 260: character maps to < undefined>
If I remove the last line, so the code looks like this:
import os.path
file_to_read = open("file_name.txt", "r")
Then I don't get any errors.
Which points me towards a problem with lines = file_to_read.readlines()
, but I cannot see anything wrong with it.