解决Python读取文件时出现UnicodeDecodeError: 'gbk' codec can't decode 亦凉 2022-07-16 03:48 118阅读 0赞 转自[http://www.cnblogs.com/arctique/p/5699620.html][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()) [http_www.cnblogs.com_arctique_p_5699620.html]: http://www.cnblogs.com/arctique/p/5699620.html
还没有评论,来说两句吧...