Skip to content

Instantly share code, notes, and snippets.

@evz
Last active December 20, 2015 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evz/6178297 to your computer and use it in GitHub Desktop.
Save evz/6178297 to your computer and use it in GitHub Desktop.
Take a CSV and make it an HTML table
import csv
def table_it(fname):
outs = '<table id="abms" class="dataTable" aria-describedby="abms_info">'
with open(fname, 'rb') as f:
reader = csv.reader(f)
headers = reader.next()
outs += '<thead><tr>'
outs += ''.join(['<th>%s</th>' % h for h in headers])
outs += '</tr></thead><tbody>'
for row in reader:
outs += '<tr>'
outs += ''.join(['<td>%s</td>' % r for r in row])
outs += '</tr>'
outs += '</tr></tbody></table>'
out = open('out.html', 'wb')
out.write(outs)
if __name__ == "__main__":
import sys
fname = sys.argv[1]
table_it(fname)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment