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

前端 未结 10 859
抹茶落季
抹茶落季 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:52

    You could resolve the problem with:

    for line in open(your_file_path, 'rb'):
    

    'rb' is reading file in binary mode. Read more here. Hope this will help!

提交回复
热议问题