cowboy me, 2.0: jose nazario beauty and the street


csv2xml.py



whipped this up for someone earlier today:
#!/usr/bin/env python

import cgi, csv, sys, cElementTree

reader = csv.reader(open(sys.argv[1], "r"), quoting=csv.QUOTE_NONE) lineno = -1 root = cElementTree.Element('document', {'name': sys.argv[1], 'generator': 'csv2xml.py'}) for line in reader: lineno += 1 if lineno == 0: fields = line continue elem = cElementTree.SubElement(root, 'line', {'lineno': str(lineno)}) for i, field in enumerate(fields): subelem = cElementTree.Element(cgi.escape(field.replace(' ', '_').replace('&', 'and'))) subelem.text = cgi.escape(line[i]) elem.append(subelem)

cElementTree.dump(root)


similar to http://csv2xml.sourceforge.net/.

|

----

next Sunday, Oct 26, 2008 @ 06:16pm | previous Friday, Oct 03, 2008 @ 08:24am | archives

Last modified: Friday, Oct 24, 2008 @ 02:05pm
Weblog Commenting and Trackback by HaloScan.com

Your Ad Here

copyright © 2002-2005 jose nazario, all rights reserved.