-
-
Save bobycv06fpm/0b152cc5022f2acf9aaaf8abcae14c8f to your computer and use it in GitHub Desktop.
convert csv to wiki table
This file contains 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
""" | |
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