1 |
4654
|
aaronmk
|
#!/usr/bin/env python
|
2 |
|
|
# Inserts a new, empty spreadsheet column before the given index.
|
3 |
|
|
|
4 |
|
|
import csv
|
5 |
|
|
import sys
|
6 |
|
|
|
7 |
|
|
def main():
|
8 |
4978
|
aaronmk
|
try: _prog_name, col_num, name, fill_value = sys.argv
|
9 |
4654
|
aaronmk
|
except ValueError: raise SystemExit('Usage: '+sys.argv[0]
|
10 |
4978
|
aaronmk
|
+' <in col# col_name fill_value [| '+sys.argv[0]
|
11 |
|
|
+' col_2# col_2_name col_2_value]... >out')
|
12 |
4654
|
aaronmk
|
col_num = int(col_num)
|
13 |
|
|
|
14 |
|
|
# Transform input
|
15 |
|
|
reader = csv.reader(sys.stdin)
|
16 |
|
|
writer = csv.writer(sys.stdout)
|
17 |
|
|
is_header = True
|
18 |
|
|
value = name
|
19 |
|
|
for row in reader:
|
20 |
|
|
row.insert(col_num, value)
|
21 |
|
|
if is_header:
|
22 |
|
|
is_header = False
|
23 |
4978
|
aaronmk
|
value = fill_value
|
24 |
4654
|
aaronmk
|
writer.writerow(row)
|
25 |
|
|
|
26 |
|
|
main()
|