Python 3 UnicodeDecodeError: ascii codec cannot decode byte 0xe2 at position 0: serial number not in range (128)

I implement this notepad on Windows with Python 3.5.3 and received the following error when calling load_vectors (). I tried to post different solutions, but none of them worked.

<ipython-input-86-dd4c123b0494> in load_vectors(loc)
      1 def load_vectors(loc):
      2     return (load_array(loc+'.dat'),
----> 3         pickle.load(open(loc+'_words.pkl','rb')),
      4         pickle.load(open(loc+'_idx.pkl','rb')))

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 0: ordinal not in range(128)
+7
source share
3 answers

You should probably specify the encoding for pickle.load(f, encoding='latin1'), but make sure that all characters in your file follow the encoding.

"ASCII", . , . . .

latin1 , encoding='bytes', .

+3

, CSV :

with open(self.path + "/review_collection.txt", "r", encoding="utf-8") as f:
    read = f.read().splitlines()
    for row in read:
        print(row)
+11
+1

Source: https://habr.com/ru/post/1685059/


All Articles