[Tutor] Writing dictionaries to a file

Kent Johnson kent37 at tds.net
Mon Apr 7 21:50:05 CEST 2008


Jerrold Prothero wrote:
>  
> I've been trying to understand how writing a dictionary to a file & reading
> it back should work.
>  
> It's been suggested that if I had a clue, I'd use pickle, but since I 
> started
> looking at the csv (comma separated values) module, which also supports
> writing dictionaries out to a file, I at least wanted to understand how it's
> supposed to work with csv.

The csv module writes one dictionary per row of the CSV file. It is 
intended for storing repeated data, though you could just read and write 
a single row. When it reads the data back, everything will be returned 
as a string. This may not be the best fit for your situation.

Kent


More information about the Tutor mailing list