Posted By

tclancy on 03/02/11


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

jeremydouglass


Simple CSV File Parser


 / Published in: Python
 

  1. import os
  2. import csv
  3.  
  4. data = csv.reader(open('source.csv'))
  5. fields = data.next()
  6. output = '<?php %s$countries = array(%s' % (os.linesep, os.linesep)
  7. for row in data:
  8. if row[0]:
  9. output += '%s"%s%s" => array("country" => "%s", "email" => "%s"),' \
  10. % (os.linesep, row[1], row[4], row[0], row[5])
  11. output = output[:-1] + '); ?>'
  12.  
  13. f = open('/path/to/destination.php', 'w')
  14. f.write(output)
  15. f.close()

Report this snippet  

You need to login to post a comment.