lalo...@charter.net wrote:
> I am trying to build a list of dictionaries for the report writer and have
> run into a strange one.  I need to build multiple records with some
> duplicated data.  

It is you. Python dicts (and lists) are mutable, whereas most other types are 
immutable. So when you append a dict to a list, the list references a pointer 
to the 
dict. Then you change an element in *that same dict*, and append it again, and 
the 
list now has 2 pointers to the same dict.

In your case, you don't need a deep copy, so this should suffice:

> #1
> rcdlist=[]
> rcd={'assigned': True, 'status': 'ASSIGNED TO CLASS ID: 10762 - 09/12/2009',
> 'enrollid': 27531, 'cname': u'Adams, Andrew                   '}
> print rcd
> rcdlist.append(rcd)
> print rcdlist
> 
> #2

-----> rcd = rcd.copy()
> rcd['status']='somthing else'
> print rcd
> rcdlist.append(rcd)
> print rcdlist

Don't feel bad. I got burned by this at least twice, and they were doozies.

Paul



_______________________________________________
Post Messages to: Dabo-users@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: http://leafe.com/archives/byMID/4a8b8a61.1000...@ulmcnett.com

Reply via email to