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 修复成功!

 

你可能感兴趣的:(python,python)