Last active
August 29, 2015 14:25
-
-
Save objcode/ea35432af6a93ad9eb34 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import csv | |
import sys | |
def process(fname, ofname): | |
with open(fname, 'rb') as csvfile: | |
with open(ofname, 'wb') as writefile: | |
out_lines = 0; | |
reader = csv.reader(csvfile) | |
writer = csv.writer(writefile) | |
for row in reader: | |
print "Processing:", row | |
start = int(row[0]) | |
end = int(row[1]) | |
value = row[2] | |
for key in range(start, end + 1): | |
out_lines += 1 | |
writer.writerow([key, value]) | |
print "Output", out_lines, "lines to", ofname | |
if __name__ == '__main__': | |
process(sys.argv[1], sys.argv[2]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
in.csv
1,17,4
18,29,5
Run
> python sequence_output.py in.csv out.csv
Processing: ['1', '17', '4']
Processing: ['18', '29', '5']
Output 29 lines to out.csv
out.csv
1,4
2,4
3,4
4,4
5,4
6,4
7,4
8,4
9,4
10,4
11,4
12,4
13,4
14,4
15,4
16,4
17,4
18,5
19,5
20,5
21,5
22,5
23,5
24,5
25,5
26,5
27,5
28,5
29,5