with open('example.html') as of:
    of.write('<html><table>')
for index, row in enumerate(data):
    if index == 0:
        of.write('<th>')
else:
    of.write('<tr>')
for cell in row:
    of.write('<td>' + cell + '</td>')
if index == 0:
    of.write('</th>')
else:
    of.write('</tr>')
of.write('</table></html>')
Creating publication quality tables in python