Skip to content

Instantly share code, notes, and snippets.

@enigmaticape
Created November 5, 2012 12:15
Show Gist options
  • Save enigmaticape/4016913 to your computer and use it in GitHub Desktop.
Save enigmaticape/4016913 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 )
@enigmaticape
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment