Skip to content

Instantly share code, notes, and snippets.

@heenashree
Forked from enigmaticape/csv2html.py
Created September 19, 2017 04:52
Show Gist options
  • Save heenashree/f7ccedb9df774ad9c6ae6954fdd4b6ab to your computer and use it in GitHub Desktop.
Save heenashree/f7ccedb9df774ad9c6ae6954fdd4b6ab to your computer and use it in GitHub Desktop.
Very simple CSV to HTML table in Python
#!/usr/bin/python
import sys
import os
import csv
import string
if len( sys.argv ) < 2 :
sys.stderr.write( sys.argv[ 0 ] +
": usage - " +
sys.argv[ 0 ] + " [.csv file name]\n" )
sys.exit()
if not os.path.exists(sys.argv[ 1 ]):
sys.stderr.write( sys.argv[ 1 ] + " not found \n" )
sys.exit()
with open( sys.argv[ 1 ], 'rb') as csvfile:
table_string = ""
reader = csv.reader( csvfile )
for row in reader:
table_string += "<tr>" + \
"<td>" + \
string.join( row, "</td><td>" ) + \
"</td>" + \
"</tr>\n"
sys.stdout.write( table_string )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment