Gr8! tyvm 

> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]] On Behalf Of Paul McNett
> Sent: Wednesday, August 19, 2009 1:15 AM
> To: Dabo Users list
> Subject: Re: [dabo-users] Python bug or is it me?
> 
> [email protected] 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
> 
> 
> 
[excessive quoting removed by server]

_______________________________________________
Post Messages to: [email protected]
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/!~!uenerkvcmdkaaqacaaaaaaaaaaaaaaaaabgaaaaaaaaaafa2fnyupuomnfpiynbeqckaaaaqaaaaqbe5wgegdk2u5yf8s93b1weaa...@charter.net

Reply via email to