Advertisement
Zboyd

CSVCombine

Dec 15th, 2014
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. #!/usr/bin/python
  2. import csv
  3. import glob
  4. import os
  5. import sys
  6.  
  7. input_path = sys.argv[1]
  8. output_file = sys.argv[2]
  9.  
  10. my_columns = ['Street', 'Booked?', 'Notes']
  11.  
  12. for input_file in glob.glob(os.path.join(input_path, '*.csv')):
  13.         with open(input_file, 'rU') as csv_in_file:
  14.                 filereader = csv.reader(csv_in_file, delimiter=',')
  15.                 filewriter = csv.writer(output_file, delimiter=',')
  16.                 header = next(filereader, None)
  17.                 header_list_output =[]
  18.                 for index_value in range(len(header)):
  19.                     if header[index_value] in my_columns:
  20.                         header_list_output.append(header[index_valuex`])
  21.                 filewriter.writerow(header_list_output)
  22.                 for row in filereader:
  23.                     row_list_output=[]
  24.                     for index_value in range(len(header)):
  25.                         if header[index_value] in my_columns:
  26.                             row_list_output.append(row[index_value])
  27.                     filewriter.writerow(row_list_output)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement