list.append not working?
Abhishek Jain
abhins4 at gmail.com
Thu Jul 5 12:29:36 EDT 2007
with every iteration your previous values are overwritten ('md' is a
dictionary) so thats why your are observing this ouput..
check if the following patch solves your problem
for entity in temp:
md['module']= entity.addr.get('module')
md['id']=entity.addr.get('id')
md['type']=entity.addr.get('type')
#print md
mbusentities.append(md)
md = {}
#print mbusentities
Regards
Abhi
On 7/5/07, Hardy <hhartwig at gmail.com> wrote:
>
> I experience a problem with append(). This is a part of my code:
>
> for entity in temp:
> md['module']= entity.addr.get('module')
> md['id']=entity.addr.get('id')
> md['type']=entity.addr.get('type')
> #print md
> mbusentities.append(md)
> #print mbusentities
>
> I want something like: [{'module': 'home', 'id': 123, 'type': 'core'},
> {'module': 'work', 'id': 456, 'type': 'core'}]
> md is always correct, BUT:mbusentities is wrong. Length of
> mbusentities is same of temp, so it appended everything. BUT:
> mbusentities only shows the values of the last append: [{'module':
> 'work', 'id': 456, 'type': 'core'}, {'module': 'work', 'id': 456,
> 'type': 'core'}]
>
> What's wrong?
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070705/4739ec80/attachment.html>
More information about the Python-list
mailing list