I want to make the code below to get formatted as HTML. However I'm having problem formatting it as HTML.
cur.execute("SELECT Statement")
rows = cur.fetchall()
html = """\
Date | DPC | TOTAL | Success |
---|
for row in rows:
for col in row:
print "
"print "%s".replace(" ", "") % col
print "
"print "
""""
My goal is to make it html output, however I don't know how to make the for loop output as formatted html.
解决方案
I hope this is the code you're looking for:
html = """\
Date | DPC | TOTAL | Success |
---|
for row in rows:
html = html + "
"for col in row:
html = html + "
" + col.replace(" ", "") + ""html = html + "
"html = html + "
"Every HTML tag is appended to the html string variable. You can write the contents of this html variable to file:
f = open('temp.html','w')
f.write(html)
f.close()