1
|
#!/usr/bin/env python
|
2
|
# Selects columns from a spreadsheet
|
3
|
|
4
|
import csv
|
5
|
import os.path
|
6
|
import sys
|
7
|
|
8
|
sys.path.append(os.path.dirname(__file__)+"/../lib")
|
9
|
|
10
|
import util
|
11
|
|
12
|
def main():
|
13
|
col_nums = sys.argv[1:]
|
14
|
if col_nums == []:
|
15
|
raise SystemExit('Usage: '+sys.argv[0]+' col_num... <map >columns_map')
|
16
|
col_nums = map(int, col_nums) # 0-based
|
17
|
|
18
|
# Process map
|
19
|
reader = csv.reader(sys.stdin)
|
20
|
writer = csv.writer(sys.stdout)
|
21
|
def subset(row): return util.list_subset(row, col_nums)
|
22
|
writer.writerow(subset(reader.next()))
|
23
|
for row in reader: writer.writerow(subset(row))
|
24
|
|
25
|
main()
|