Project

General

Profile

« Previous | Next » 

Revision 4654

Added ins_col

View differences:

bin/ins_col
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 = sys.argv
9
    except ValueError: raise SystemExit('Usage: '+sys.argv[0]
10
        +' <in col# col_name [| '+sys.argv[0]+' col_2# col_2_name]... >out')
11
    col_num = int(col_num)
12
    
13
    # Transform input
14
    reader = csv.reader(sys.stdin)
15
    writer = csv.writer(sys.stdout)
16
    is_header = True
17
    value = name
18
    for row in reader:
19
        row.insert(col_num, value)
20
        if is_header:
21
            is_header = False
22
            value = ''
23
        writer.writerow(row)
24

  
25
main()
0 26

  

Also available in: Unified diff