I want to take the text of a file, each new value on a new line, for example hi /n this is my question /n can u answer it?
My_list should look like this My_list[0]
should be equal to hi
, My_list[1]
should be equal to this is my question
and My_list[2]
should be equal to can u answer it?
I tried doing so using the following
with open(r'path.docx',encoding="utf8") as f:
content = f.readlines()
content = [x.strip() for x in content]
in an approach like the one i found in here How do I read a file line-by-line into a list?
Then i got a Syntax error for unicode
do i referred to this link Why do I get a SyntaxError for a Unicode escape in my file path? added r
at first and solved it for the first iteration then got this error
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte X in position Y: character maps to <undefined>
that i referred to this link to solve UnicodeDecodeError: 'charmap' codec can't decode byte X in position Y: character maps to <undefined> and added encoding="utf8"
. Still not working .
EDIT: I changed the encoding to "Latin-1"
but i didn't get the output i want from print (content)
instead i got stuff like that ['PK\x03\x04\x14\x00\x06\x00\x08\x00\x00\x00!\x00\t$\x87\
, again what i want and expect is a list where each line of the .docx file is an element(seperated by /n).