problem with dictionaries within lists

Grant Hallam gupsmail at
Wed Sep 25 10:51:48 EDT 2002

I reset the dict keys to blank strings and it works now.  
added the following after webdatabaselist(dict.append)
dict = {'Name': '','Location':'','Transit':'','Position':'','Technical_Knowledge':'','Like_Site':'','Resolve_Tech_Issues':'','Easy_Navigation':'','Publish_Comments':'','Answered_No':'','Find_Support':'','Find_Support_Other':'','Find_Information':'','Which_LEOnet_Site':'','Find_Information_Other':'','Visit_Again':'','Visited_Old_Site':'','Time_Spent':'','Comments':'','B1':''}
and it works ok now.  Seems like a bit of a hack, have to think of a
better way later.

On Wed, 25 Sep 2002 02:11:14 -0700, Alex Martelli wrote:

> Grant Hallam wrote:
>         ...
>>  However, the list seems to get populated with the same dictionary
>         ...
>> webdatabaselist.append(dict)
> Of course -- you ARE appending the same dict over ands over (AFAICT --
> you're probably using tabs for indentation, making your code hard to
> comprehend for those who read news with KDE's KNode [or MS's OE] as tabs
> don't show there... use spaces, NOT tabs...).
> Anyway, you probably need something like:
> webdatabaselist.append(dict.copy())
> dict = {}
> either might suffice, but generally you'll need to copy the current dict
> AND make dict empty for the next leg of the loop, if I get the general
> drift.  If you do rebind name dict to {} for the next leg, then you
> don't need the call to the copy method.
> Alex

More information about the Python-list mailing list