-
-
Save heenashree/f7ccedb9df774ad9c6ae6954fdd4b6ab to your computer and use it in GitHub Desktop.
Very simple CSV to HTML table in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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