import csv import os.path import sys if len( sys.argv ) != 2: print "csv2wiki [FILE]" sys.exit(0) fname = sys.argv[1] if not os.path.exists( fname ): print "Cannot find file ", fname sys.exit(0) #if there row will be error first_row = True with open(fname,"rb") as f: cr = csv.reader( f, delimiter=',', quotechar='"' ) for row in cr: #special case for first row if first_row: print """ {| class="wikitable sortable" |- """ for cell in row: print "!|",cell first_row = False continue print "|-" for cell in row: print "||", cell print "|}"