[Tutor] Writing dictionaries to a file

Luke Paireepinart rabidpoobear at gmail.com
Mon Apr 7 19:16:33 CEST 2008


Jerrold Prothero wrote:
>  
> I've been trying to understand how writing a dictionary to a file & 
> reading
> it back should work.
>  [snip]
>  
> Here are three guesses at how to call writerows, with error traces.
>  [snip]
> 2)
>  
> w.writerows(d)
>  
> Traceback (most recent call last):
>   File "<pyshell#13>", line 1, in <module>
>     w.writerows(d)
>   File "C:\Python25\lib\csv.py", line 129, in writerows
>     rows.append(self._dict_to_list(rowdict))
>   File "C:\Python25\lib\csv.py", line 118, in _dict_to_list
>     for k in rowdict.keys():
> AttributeError: 'str' object has no attribute 'keys'
This error sounds like d is a string, not a dictionary.  Are you sure 
it's a dictionary?
-Luke


More information about the Tutor mailing list