0
点赞
收藏
分享

微信扫一扫

UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xcf in position 39: invalid continuation byte


文章目录

  • ​​1 错误重现​​
  • ​​2 解决办法​​

1 错误重现

使用读取的代码:

def readText(text_file_path):
with open(text_file_path) as f:
content = f.read()
return content

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcf in position 39: invalid continuation byte

原因是编码问题,更换编码方式就可以。

2 解决办法

使用 ​​gbk​​编码,

def readText(text_file_path):
with open(text_file_path, encoding='gbk') as f:
content = f.read()
return content

举报

相关推荐

0 条评论