码迷,mamicode.com
首页 > 其他好文 > 详细

UnicodeDecodeError: 'utf-8' codec can't decode byte

时间:2019-02-22 12:21:38      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:erro   int   decode   ret   pos   str   this   ble   tty   

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

I tried to solve this and add an extra parameter in 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! Please help.

 

解决方案:

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.

UnicodeDecodeError: 'utf-8' codec can't decode byte

标签:erro   int   decode   ret   pos   str   this   ble   tty   

原文地址:https://www.cnblogs.com/Allen-rg/p/10417444.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!