沒有output.html文件生成
我用的是是python 3.5版本,打印結(jié)果倒是對的,可是沒有生成output.html文件,哪位大神知道怎么解決嗎?一下是我的代碼:
import sys
class HtmlOutputer(object):
? ?def __init__(self):
? ? ? ?self.datas = []
? ?def collect_data(self, data):
? ? ? ?if data is None:
? ? ? ? ? ?return
? ? ? ?self.datas.append(data)
? ?def output_html(self):
? ? ? ?fout = open('output.html', mode='w', encoding='utf-8')
? ? ? ?fout.write("<html>")
? ? ? ?fout.write("<head><meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\"></head>")
? ? ? ?fout.write("<body>")
? ? ? ?fout.write("<table>")
? ? ? ?count = 0
? ? ? ?for data in self.datas:
? ? ? ? ? ?fout.write("<tr>")
? ? ? ? ? ?fout.write("<td>%d</td>" % count)
? ? ? ? ? ?fout.write("<td>%s</td>" % data['url'])
? ? ? ? ? ?fout.write("<td>%s</td>" % data['title'].encode('utf-8'))
? ? ? ? ? ?fout.write("<td>%s</td>" % data['summary'].encode('utf-8'))
? ? ? ? ? ?fout.write("</tr>")
? ? ? ? ? ?count += 1
? ? ? ?fout.write("</table>")
? ? ? ?fout.write("</body>")
? ? ? ?fout.write("</html>")
? ? ? ?fout.flush()
? ? ? ?fout.close()
? ? ? ?print(sys.getdefaultencoding())
2016-04-09
看有沒有生成權(quán)限。