問題:
Here is my code,這是我的代碼,
for line in open('u.item'):
# Read each line
Whenever I run this code it gives the following error:每當我運行此代碼時,它都會出現以下錯誤:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 2892: invalid continuation byte UnicodeDecodeError: 'utf-8' 編解碼器無法解碼位置 2892 中的字節 0xe9:繼續字節無效
I tried to solve this and add an extra parameter in open().我試圖解決這個問題並在 open() 中添加一個額外的參數。 The code looks like:代碼如下:
for line in open('u.item', encoding='utf-8'):
# Read each line
But again it gives the same error.但它再次給出了同樣的錯誤。 What should I do then?那我該怎麼辦?
解決方案:
參考一: https://en.stackoom.com/question/1Kehj參考二: https://stackoom.com/question/1Kehj