Created
October 16, 2015 16:30
-
-
Save caiosba/ca1309f1201609657f26 to your computer and use it in GitHub Desktop.
Python script to convert from CSV to a pretty ASCii table
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 | |
from __future__ import print_function | |
import prettytable | |
import csv | |
import sys | |
def main(argv): | |
if len(sys.argv) != 3: | |
print('Usage: python csv2table.py [input file] [output]\n') | |
exit(1) | |
inputfile = sys.argv[1] | |
outputfile = sys.argv[2] | |
table = None | |
with open(inputfile, 'rb') as csvfile: | |
content = csv.reader(csvfile, delimiter=',', quotechar='"') | |
for row in content: | |
if table is None: | |
table = prettytable.PrettyTable(row) | |
else: | |
table.add_row(row) | |
output = open(outputfile, 'w') | |
print(table, file=output) | |
print('Done.\n') | |
if __name__ == "__main__": | |
main(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment