[Tutor] Converting a string into dictionary references
Gerhardus Geldenhuis
gerhardus.geldenhuis at gmail.com
Mon Apr 23 14:56:17 CEST 2012
Hi
Appologies about the subject I could not think of a better description.
I have this very simple function:
def readcsvfile(filename):
f = open(filename, 'ro')
csvdata = csv.DictReader(f)
for row in csvdata:
print row["column3"]+','+row["column1"]
I have another inputfile that will be comma separated list of values.
Eg:
column3,column4,column10
The idea is that I use this inputfile to tranform the original csv file. I
thus want a new file with only the specified columns. I am sure there is an
elegant way of doing this but I am not sure how to convert my print
statement into something more dynamic. Any pointers would be appreciated.
Regards
--
Gerhardus Geldenhuis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120423/8dda3169/attachment.html>
More information about the Tutor
mailing list