您的位置:首页 > 编程语言 > Python开发

解决Python读取文件时出现UnicodeDecodeError: 'gbk' codec can't decode

2016-10-02 13:36 603 查看
转自http://www.cnblogs.com/arctique/p/5699620.html

出问题的代码:


if __name__ == '__main__':
fileHandler = open('../report.html', mode='r')

report_lines = fileHandler.readlines()
for line in report_lines:
print(line.rstrip())


解决代码:

if __name__ == '__main__':
fileHandler = open('../report.html', mode='r', encoding='UTF-8')

report_lines = fileHandler.readlines()
for line in report_lines:
print(line.rstrip())
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  pythonencoding
相关文章推荐