Project

General

Profile

1
#!/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
    try: _prog_name, col_num, name, fill_value = sys.argv
9
    except ValueError: raise SystemExit('Usage: '+sys.argv[0]
10
        +' <in col# col_name fill_value [| '+sys.argv[0]
11
        +' col_2# col_2_name col_2_value]... >out')
12
    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
            value = fill_value
24
        writer.writerow(row)
25

    
26
main()
(30-30/69)