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

阅读 115

2022-05-27


文章目录

  • ​​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)

0 0 举报