I have a text file with Hindi text lines(about 5400000 lines) in it. I want to save these lines in a string array in python. I tried this code:
f = open("cleanHindi_Translated.txt" , "r") array = [] for line in f: array.append(line) print(array) But I am getting an error:
Traceback (most recent call last): File "hindi.py", line 11, in <module> for line in f: File "C:\Users\Preeti\AppData\Local\Programs\Python\Python37\lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 124: character maps to <undefined> PS C:\Users\Preeti\Downloads\Compressed> python hindi.py Traceback (most recent call last): File "hindi.py", line 11, in <module> for line in f: File "C:\Users\Preeti\AppData\Local\Programs\Python\Python37\lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 124: character maps to <undefined> I don't understand on what I did wrong here.
.append(line).opendefinitely takes an encoding and your error message shows that the encoding is wrong.