python读文件出现错误解决方法

python读文件经常会出现 UnicodeDecodeError: 'gbk' codec can't decode byte 0xbd in position 764: illegal multibyte sequence

解决方法:
以"rb",方式读再以一定的方式解码,如"UTF-8","UTF-16", "gbk"

with open(log_path, 'rb') as fd:
        lines = [l.decode('utf8', 'ignore') for l in fd.readlines()]         

posted @ 2019-11-18 20:41  michaelchengjl  阅读(584)  评论(0编辑  收藏  举报