1. “UnicodeDecodeError: ‘gbk’ codec can’t decode
with open(filename, 'r') as f:
data = f.read()
将其改写为:
with open(filename, 'rb') as f:
data = f.read()
但这样读取到的文件内容,不可直接读取。为了阅读的方便,可进一步为其指定编码类型:
with open(filename, 'r', encoding='utf-8') as f:
data = f.read()