UnicodeDecodeError: 'gbk' codec can't decode byte 0xad in position 519: illegal multibyte sequence

解决办法:

加上encoding='utf-8'

1、原来

with open('xx.txt') as f:
    content = f.read()

报错

 UnicodeDecodeError: 'gbk' codec can't decode byte 0xad in position 519: illegal multibyte sequenc
e

2、修改

with open('xx.txt', encoding='utf-8') as f:
    content = f.read()

bug 修复成功!

猜你喜欢

转载自blog.csdn.net/weixin_41596463/article/details/94396507