Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Peter Otten <__peter__@web.de> Newsgroups: comp.lang.python Subject: Re: In Python 3, how to append a nested dictionary to a shelve file with the added difficulty of using a for loop? Date: Tue, 22 Dec 2015 12:45:59 +0100 Organization: None Lines: 26 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: news.uni-berlin.de r7smHlzwjsjeIwEf7aaO2ABPVXE9UJklcgNrPo+tBXNA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'subject:file': 0.07; "person's": 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:using': 0.09; 'def': 0.13; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'wrote:': 0.16; 'helper': 0.18; '>>>': 0.20; 'needed.': 0.23; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'mostly': 0.27; 'too.': 0.30; 'becomes': 0.30; 'changing': 0.34; 'that,': 0.34; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'two': 0.37; 'thanks': 0.37; 'received:org': 0.37; 'things': 0.38; 'several': 0.38; 'data': 0.39; 'subject:the': 0.39; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'received:de': 0.40; 'response.': 0.66; 'stated': 0.70; 'clearer': 0.84 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: p57bd8b89.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:100722 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.