Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import csv
- import os
- #f = str(sys.argv[1])
- f = str(sys.argv[1]) #sys.argv[1] is the file that is dropped onto the script
- g = str(os.getcwd() + r'\RECURSIVEHIERACHY.csv') #output is the current working directory + filename <-
- #print g if you can't find the file!!!
- csvdata = csv.reader(open(f))
- def recursesearch(line):
- try:
- if line[-3] in dic.keys():
- line.extend(dic[line[-3]][-3:])
- recursesearch(line)
- except IndexError:
- return
- block = []
- for item in csvdata:
- block.append(item)
- dic = {}
- for line in block:
- dic[line[0]] = line[:]
- for line in block:
- recursesearch(line)
- output = csv.writer(open(g, 'wb'))
- for line in block:
- output.writerow(line)
Add Comment
Please, Sign In to add comment