List of Dictionaries

Lenny Self lenny.self at attbi.com
Fri Mar 8 00:57:50 EST 2002


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)
    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.

{'sku': 'BIO-09', 'city': 'Rancho Palos Verdes', 'shipMethod': 'media mail',
'shipTo': '3456 Address Dr.', 'listingID': '38fh49dhfm4', 'zip': '90275',
'shippedby': 'email at address.com', 'url': 'url.goes.here.com', 'country':
'USA', 'address2': '', 'timeOfSale': '02-07-2002 09:27:35', 'buyerEmail':
'another.email at address.com', 'purchaseDate': '02-07-2002 09:27:35', 'item':
'The Rise of Theodore Roosevelt  by Morris, Edmund', 'state': 'CA',
'transaction': '700106169851', 'buyerName': 'Someone S. Name', 'address1':
'1234 Address Lane, 'condition': 'Good'}

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'}

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

Thanks again for your help.

    -- Lenny

"Erik Max Francis" <max at alcyone.com> wrote in message
news:3C88186F.6BEFA3D2 at alcyone.com...
> Lenny Self wrote:
>
> > When I add the first dictionary element to the list all is well.  When
> > I add the second element to the list both the first and second element
> > reference the second dictionary that was added.  The behavior
> > continues whenever I add an element.  So, if I add, say 50
> > dictionaries, all of the listes elements reference the last dictionary
> > I added.
> >
> > I don't have the code with me right now, but I can assure you it is
> > easy as this:
>
> The problem you're having crucially depends on you doing something wrong
> in the details of your implementation.  You're going to have to show us
> the _exact_ code that is causing this problem or it will be impossible
> to help you.
>
> --
>  Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
>  __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
> /  \ Laws are silent in time of war.
> \__/ Cicero
>     Esperanto reference / http://www.alcyone.com/max/lang/esperanto/
>  An Esperanto reference for English speakers.





More information about the Python-list mailing list