问题:
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