forked from Te-k/analyst-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsv2md.py
More file actions
executable file
·23 lines (19 loc) · 806 Bytes
/
csv2md.py
File metadata and controls
executable file
·23 lines (19 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#! /usr/bin/python2
import csv
import argparse
import sys
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Convert a csv to a Markdown file')
parser.add_argument('CSVFILE', help='CSV file to be converted')
parser.add_argument('-n', '--no-header', help="No header in the CSV file", action="store_true")
parser.add_argument('-d', '--delimiter', default=",",
help="No header in the CSV file")
args = parser.parse_args()
firstline = not args.no_header
with open(args.CSVFILE, 'r') as csvfile:
reader = csv.reader(csvfile, delimiter=',')
for row in reader:
print("|%s|" % "|".join(row))
if firstline:
print(("|:---------------------" * len(row)) + "|")
firstline = False