Posted By

jachin on 12/15/10


Tagged

files csv pipes argparse


Versions (?)

Convert CSV file to Pipe Delineated File


 / Published in: Python
 

  1. import argparse
  2. import csv
  3.  
  4. parser = argparse.ArgumentParser(description='Converts a regular CSV to a piple delimited file with no quotes.')
  5.  
  6. parser.add_argument('csv_file', help='The CSV file to parse.')
  7.  
  8. args = parser.parse_args()
  9.  
  10. csv_reader = csv.reader(open(args.csv_file, 'rb'), delimiter=',', quotechar='"')
  11.  
  12. for row in csv_reader:
  13. row = '|'.join(row)
  14.  
  15. row = row.replace('\n', '')
  16. row = row.replace('\r', '')
  17.  
  18. print row

Report this snippet  

You need to login to post a comment.