Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.020 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'instance,': 0.05; 'character,': 0.07; 'list)': 0.09; 'syntax': 0.11; 'am,': 0.13; 'wrote:': 0.15; '(sun,': 0.16; 'both.': 0.16; 'dictionaries': 0.16; 'nesting': 0.16; 'received:mindspring.com': 0.16; 'subject:database': 0.16; 'subject:wrong': 0.16; 'x-mailer:apple mail (2.1084)': 0.16; 'pm,': 0.16; '>>>': 0.16; 'header:In-Reply- To:1': 0.22; '(where': 0.23; 'dictionary': 0.23; 'structure': 0.23; 'libraries': 0.25; 'specify': 0.25; 'xml': 0.25; 'tables': 0.28; 'example': 0.30; 'match': 0.30; 'config': 0.30; 'nested': 0.30; 'tuples': 0.30; 'subject:?': 0.31; 'named': 0.32; 'andrew': 0.32; 'comment': 0.33; 'to:addr:python-list': 0.34; 'instead': 0.34; 'received:24': 0.34; 'agree': 0.35; 'charset:us-ascii': 0.36; 'file': 0.36; 'some': 0.37; 'but': 0.37; 'could': 0.37; 'another': 0.38; 'subject:: ': 0.38; 'problem.': 0.38; 'think': 0.38; 'header:Mime-Version:1': 0.39; "there's": 0.39; 'to:addr:python.org': 0.39; 'skip:d 20': 0.40; 'your': 0.60; 'header:Message-Id:1': 0.61; '31,': 0.64; 'encoding,': 0.84; 'ini': 0.84; 'lightweight': 0.84; 'received:69.73': 0.84; 'skip:q 30': 0.84; 'subject:should': 0.84; 'difficult.': 0.91 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Apple Message framework v1084) Subject: Re: Deeply nested dictionaries - should I look into a database or am I just doing it wrong? From: Philip Semanchuk In-Reply-To: Date: Sun, 31 Jul 2011 16:53:48 -0400 Content-Transfer-Encoding: quoted-printable References: To: Lista-Comp-Lang-Python list X-Mailer: Apple Mail (2.1084) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - deimos.nocdirect.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - semanchuk.com X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1312149953 news.xs4all.nl 23864 [2001:888:2000:d::a6]:57256 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:10636 On Jul 31, 2011, at 4:04 PM, Thorsten Kampe wrote: > * Andrew Berg (Sun, 31 Jul 2011 13:36:43 -0500) >> On 2011.07.31 02:41 AM, Thorsten Kampe wrote: >>> Another approach would be named tuples instead of dictionaries or >>> flat SQL tables. >> What would the advantage of that be? >=20 > QueueItem.x264['avs']['filter']['fft3d']['ffte'] would be=20 > QueueItem.x264.avs.filter.fft3d.ffte. I recently "migrated" from a=20 > syntax of - example - datetuple[fieldpositions['tm_year'][0]] (where=20= > fieldpositions was a dictionary containing a list) to=20 > datetuple.tm_year_start which is much more readable. >=20 > The advantage of a SQL(ite) database would be simple flat tables but=20= > accessing them would be more difficult. >=20 > Even a INI config file structure could match your problem. INI files are OK for lightweight use, but I find them very fragile. = Since there's no specification for them, libraries don't always agree on = how to read them. For instance, some libraries treat # as the comment = character, and others think it is ; and others accept both. There's no = standard way to specify the encoding, and, as would be critical to the = OP who is nesting dicts inside of dicts, not all INI file libraries = accept nested sections. To the OP -- if you're looking to write this to disk, I recommend XML or = SQLite.=20 JMHO, Philip=