-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsplit.py
More file actions
27 lines (21 loc) · 707 Bytes
/
Copy pathsplit.py
File metadata and controls
27 lines (21 loc) · 707 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""Split a CSV into columns, one file per column."""
from __future__ import print_function
import csv
import sys
def open_file(fpath, mode):
return open(fpath, mode)
def split(fin, open_file=open_file):
reader = csv.reader(fin, delimiter='|')
header = next(reader)
paths = ['gitignore/col-%d.txt' % col_num for col_num, col_name in enumerate(header)]
fouts = [open(path, 'wb') for path in paths]
for row in reader:
for col_num, col_value in enumerate(row):
fouts[col_num].write(col_value + b'\n')
for fout in fouts:
fout.close()
return paths
if __name__ == '__main__':
paths = split(sys.stdin)
for path in paths:
print(path)