CSV Module questions

Dave Cole djc at object-craft.com.au
Mon Sep 8 21:50:04 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).

The csv module is new in Python 2.3 so we can probably assume that
.iteritems() is there :-).

- Dave

-- 
http://www.object-craft.com.au




More information about the Python-list mailing list