List of Dictionaries

Quinn Dunkan quinn at cruzeiro.ugcs.caltech.edu
Fri Mar 8 04:11:52 EST 2002


On Fri, 08 Mar 2002 05:57:50 GMT, Lenny Self <lenny.self at attbi.com> wrote:
>Here's a chunk of the real code.
>
>f = open("c:/test.dbx", "rb")
>msgs = ReadOEFile(f) # Using 3rd party code to get email out of an Outlook
>mailbox
>
>masterList = []
>
>for mesg in msgs:
>    email = Read_OE_Message(f, mesg.position) # returns a string containg an
>individual email
>    data = MailData(email).getOrderInfo() # Looks though email and sucks out
>important information and returns it as a dictionary
>   # if I print the data variable here It shows data from each of the
>messages (all unique)

Try printing id(data).  If the numbers are the same, getOrderInfo is returning
the same dict for some reason (likely a bug since that's a strange thing to
do).  In that case, you should fix MailData.  If it's 3rd party code and
you can't or don't want to, do 'masterList.append(data.copy())'.

>    masterList.append(data)
>    # If I print the masterList dictionary here it has the right number of
>elements in the list but they are all the same.
>
>Each of the origional dictionaries containd the following key:value pairs
>being appended to the masterList looks something like this.
...
>An interesting piece of info is that when I append a subset of this data,
>say just to key value pairs it works  Like just:
>
>{'sku':'BIO-09','item':'The Rise of Theodore Roosivelt by Morris, Edmund'}

Possibly because making a subset creates a new dict, which avoids the aliasing
problem.

>Same code just smaller dictionary.  Could I be surpassing some sort of
>limit.  I woudn't think this dictionry is that big.

No, you are not exceeding a limit.



More information about the Python-list mailing list