Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #100722 > unrolled thread

Re: In Python 3, how to append a nested dictionary to a shelve file with the added difficulty of using a for loop?

Started byPeter Otten <__peter__@web.de>
First post2015-12-22 12:45 +0100
Last post2015-12-22 12:45 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: In Python 3, how to append a nested dictionary to a shelve file with the added difficulty of using a for loop? Peter Otten <__peter__@web.de> - 2015-12-22 12:45 +0100

#100722 — Re: In Python 3, how to append a nested dictionary to a shelve file with the added difficulty of using a for loop?

FromPeter Otten <__peter__@web.de>
Date2015-12-22 12:45 +0100
SubjectRe: In Python 3, how to append a nested dictionary to a shelve file with the added difficulty of using a for loop?
Message-ID<mailman.56.1450784776.2237.python-list@python.org>
Aaron Christensen wrote:

> Thanks for the response!  Several things you stated definitely got me
> thinking.  I really appreciate the response.  I used what you said and I
> am able to accomplish what I needed.

Perhaps it becomes clearer when you write two helper functions

def read_record(key):
    return db[key]

def write_record(key, value):
    db[key] = value

Changing a person's data then becomes

person_data = read_record("person_1")
person_data["age"] = 123
write_record("person_1", person_data)

Also, I was mostly paraphrasing

>>> help(shelve)

so you might read that, too.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web