Skip to content

Instantly share code, notes, and snippets.

@0ncorhynchus
Last active April 2, 2024 21:56
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save 0ncorhynchus/6605020 to your computer and use it in GitHub Desktop.
Save 0ncorhynchus/6605020 to your computer and use it in GitHub Desktop.
convert csv to wiki table
"""
Usage: python csv2wikitable.py csv_file
-----
input: csv format
output: wiki table format
"""
import sys
if __name__ == '__main__':
argvs = sys.argv
argcs = len(argvs)
if argcs != 2:
sys.stderr.write('Usage: python %s csv_file\n' % argvs[0])
sys.exit(1)
filename = argvs[1]
infile = open(filename, 'r')
inlines = infile.readlines()
infile.close()
outlines = []
for line in inlines:
outlines.append(line.replace(',','|'))
outfile = open('wiki_'+filename, 'w')
outfile.write('{|\n')
outfile.writelines(outlines)
outfile.write('|}')
outfile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment