Return to Snippet

Revision: 42261
at March 2, 2011 10:09 by tclancy


Initial Code
import os
import csv

data = csv.reader(open('source.csv'))
fields = data.next()
output = '<?php %s$countries = array(%s' % (os.linesep, os.linesep)
for row in data:
	if row[0]:
		output += '%s"%s%s" => array("country" => "%s", "email" => "%s"),' \
		 % (os.linesep, row[1], row[4], row[0], row[5])
output = output[:-1] + '); ?>'

f = open('/path/to/destination.php', 'w')
f.write(output)
f.close()

Initial URL

                                

Initial Description

                                

Initial Title
Simple CSV File Parser

Initial Tags

                                

Initial Language
Python