“for line in…” results in UnicodeDecodeError: 'utf-8' codec can't decode byte

前端 未结 10 839
抹茶落季
抹茶落季 2020-11-22 17:15

Here is my code,

for line in open(\'u.item\'):
#read each line

whenever I run this code it gives the following error:



        
10条回答
  •  不要未来只要你来
    2020-11-22 17:34

    As suggested by Mark Ransom, I found the right encoding for that problem. The encoding was "ISO-8859-1", so replacing open("u.item", encoding="utf-8") with open('u.item', encoding = "ISO-8859-1") will solve the problem.

提交回复
热议问题