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


Groups > comp.lang.python > #95257

Re: looking for standard/builtin dict-like data object

Path csiph.com!eternal-september.org!feeder.eternal-september.org!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.033
X-Spam-Evidence '*H*': 0.93; '*S*': 0.00; 'attributes': 0.07; 'cc:addr:python-list': 0.09; 'python': 0.10; '(unlike': 0.16; 'ah,': 0.16; 'api,': 0.16; 'fly': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:object': 0.16; 'wrote:': 0.16; 'attribute': 0.18; '>>>': 0.20; 'library': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'aug': 0.20; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'compatible': 0.27; 'message-id:@mail.gmail.com': 0.27; 'looks': 0.29; 'accepts': 0.29; 'arguments,': 0.29; 'solution,': 0.29; "they'll": 0.29; 'subject:/': 0.30; 'anyone': 0.32; "can't": 0.32; 'class': 0.33; 'subject:like': 0.33; 'case,': 0.34; 'thanks!': 0.34; 'tue,': 0.34; 'received:google.com': 0.35; 'but': 0.36; 'keyword': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'expect': 0.37; 'thought': 0.37; 'creation': 0.38; 'does': 0.39; 'system.': 0.39; 'subject:-': 0.39; 'rather': 0.39; 'some': 0.40; 'easy': 0.60; 'chance': 0.60; 'your': 0.60; 'skip:u 10': 0.61; 'more': 0.63; 'our': 0.64; 'statement,': 0.66; 'chrisa': 0.84; 'upgrade,': 0.84; 'to:none': 0.91; 'subject:looking': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=0PK2WKSq5+LlyFKTZLmQZyKnfKSl1NUL61IIOHfitd0=; b=IKwCjfLlKZriV5lIlOkvOWXTTvvRDvorirbKCU+9kc8x1ouquf8qyOwbmm8nwX8fgc OD7bRY+7RG2V/xaK4mU+cG23Auaca5lHAO71W7fVxvqGGyoMhBc+myaLKLX/PkpxxK9m 5hwCp+i5k+/hI8YVOFGpLleJU1ti62Wz/RMJAlRITBBJ7VlsLn7pFtjAJT6feRdW4DHB /gd1zxWTGsJkEoFSx2Ua5D3zIkhwDc8VKmRnVdJvuUtxllMavqG5YAbrV0zqvJhXI7IX ajelJEwzq7kZ62zjf21SdCdOFiQuCH29ezDfcdHh8FqB7JtM65O2nifxgLqVTfAT429D JNKg==
MIME-Version 1.0
X-Received by 10.107.31.134 with SMTP id f128mr25184834iof.19.1439295074119; Tue, 11 Aug 2015 05:11:14 -0700 (PDT)
In-Reply-To <CAK_ErkhUGviODjHsptmb6L4GXNkBb352rXTYTVvj0MyD4dTwgg@mail.gmail.com>
References <CAPTjJmoLSZjoerPeJ5a+Nh1ftcQfqgdcF-xB=3Xn7m2WKxyjHA@mail.gmail.com> <20150811042807.GA56342@cskk.homeip.net> <CAK_ErkhUGviODjHsptmb6L4GXNkBb352rXTYTVvj0MyD4dTwgg@mail.gmail.com>
Date Tue, 11 Aug 2015 22:11:14 +1000
Subject Re: looking for standard/builtin dict-like data object
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.79.1439295076.3627.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1439295076 news.xs4all.nl 2858 [2001:888:2000:d::a6]:47586
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:95257

Show key headers only | View raw


On Tue, Aug 11, 2015 at 10:06 PM, Vladimir Ignatov <kmisoft@gmail.com> wrote:
>>>> I also thought the stdlib had some kind of "namespace" class with this
>>>> kind
>>>> of API, but I can't find it now:-(
>>>
>>>
>>> It does - types.SimpleNamespace(). It accepts keyword arguments, and
>>> will let you create more attributes on the fly (unlike a namedtuple).
>>
>>
>> Yes, that's it. Thanks!
>>
>
> Ah, sad, sad, sad.  We unfortunately stuck with built-in Python 2.6.x
> in our system.  I see from docs that SimpleNamespace is rather new
> creation (3.3+).  I know 'namedtuple' way, but don't like it as I
> prefer freedom in attribute creation/mutation.  Looks like I have to
> stuck with handmade solution for now.
>

In that case, what I would recommend is: Use your handmade solution,
but call it SimpleNamespace, and make it entirely compatible with the
Python 3.3 one. Then, when you do get a chance to upgrade, all you
need to do is change your import statement, and you're using the
standard library one. Plus, it's going to be easy for anyone else to
read - they'll already know what SimpleNamespace does and what to
expect of it, so they don't have to dig around to see what your class
is doing.

ChrisA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: looking for standard/builtin dict-like data object Chris Angelico <rosuav@gmail.com> - 2015-08-11 22:11 +1000

csiph-web