Skip to content

Instantly share code, notes, and snippets.

@bobycv06fpm
Forked from 0ncorhynchus/csv2wikitable.py
Created July 25, 2020 16:11
Show Gist options
  • Save bobycv06fpm/0b152cc5022f2acf9aaaf8abcae14c8f to your computer and use it in GitHub Desktop.
Save bobycv06fpm/0b152cc5022f2acf9aaaf8abcae14c8f 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