CSV Module questions

Scott David Daniels Scott.Daniels at Acm.Org
Mon Sep 8 13:03:39 EDT 2003


John D. wrote:
> I'm trying to understand how to use the "csv" module....
> Example (from the docs):
> # Just some stupid dictionary with key same as value.
> someiterable = {'john d': 'john d', 'fred': 'fred'}
> 
> # make the writer.
> writer = csv.writer(file("some.csv", "w"))
> for row in someiterable:
   for row in someiterable.iteritems():
>     writer.writerow(row)

I suspect the problem is that you misunderstand dictionary iteration.
Examine and understand:
	
     for row in someiterable:
         print repr(row)

     for row in someiterable.iteritems():
         print repr(row)


By the way, just use .items(), not .iteritems() if you have an older 
python (before 2.2, I believe).

-Scott David Daniels
Scott.Daniels at Acm.Org





More information about the Python-list mailing list