Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #95242
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!border2.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <cameron@cskk.homeip.net> |
| 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; 'url:pypi': 0.03; '(self,': 0.07; 'cc:addr:python-list': 0.09; '(instead': 0.09; '__init__': 0.09; 'collections': 0.09; 'kwargs': 0.09; 'def': 0.13; 'instead.': 0.15; 'producing': 0.15; '"o"': 0.16; '>in': 0.16; 'accesses': 0.16; 'api,': 0.16; 'drag': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'golding,': 0.16; 'libraries?': 0.16; 'message- id:@cskk.homeip.net': 0.16; 'simpson': 0.16; 'subject:object': 0.16; 'tuple,': 0.16; 'wrote:': 0.16; '>>>': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'martin': 0.22; 'cheers,': 0.22; 'cc:no real name:2**0': 0.22; 'passing': 0.23; 'import': 0.24; 'plain': 0.24; 'header:In-Reply-To:1': 0.24; 'module': 0.25; "i've": 0.25; 'header:User-Agent:1': 0.26; '**kwargs):': 0.29; 'dictionary': 0.29; 'subject:/': 0.30; 'code': 0.30; "i'd": 0.31; "can't": 0.32; 'knows': 0.32; 'anybody': 0.32; 'class': 0.33; 'url:python': 0.33; 'curious': 0.33; 'subject:like': 0.33; 'similar': 0.33; 'maintaining': 0.34; 'except': 0.34; 'functions.': 0.35; 'something': 0.35; 'but': 0.36; 'located': 0.36; 'url:org': 0.36; 'data.': 0.36; 'subject:: ': 0.37; 'client': 0.37; 'thought': 0.37; 'charset:us-ascii': 0.37; 'data': 0.39; 'subject:-': 0.39; 'where': 0.40; 'called': 0.40; 'some': 0.40; 'your': 0.60; 'side': 0.62; 'skip:n 10': 0.62; 'making': 0.62; 'between': 0.65; 'cameron': 0.66; 'received:61': 0.72; 'overall': 0.72; 'dict.': 0.84; 'violent': 0.84; 'glad': 0.87; 'subject:looking': 0.91; 'live.': 0.93 |
| X-Authentication-Info | Submitted using ID cskk@bigpond.com |
| X-Authority-Analysis | v=2.0 cv=RsdH3VaK c=1 sm=1 a=AjlubTDzJBxM6+wIUrLTQg==:17 a=vrnE16BAAAAA:8 a=ZtCCktOnAAAA:8 a=yEdEr6MRgwAA:10 a=uRRa74qj2VoA:10 a=pGLkceISAAAA:8 a=8AHkEIZyAAAA:8 a=4dnaHi-AAAAA:8 a=frpFGL3ZyI3Orse4n1UA:9 a=CjuIK1q_8ugA:10 a=u6qmM4khKPQA:10 a=AjlubTDzJBxM6+wIUrLTQg==:117 |
| Date | Tue, 11 Aug 2015 13:40:49 +1000 |
| From | Cameron Simpson <cs@zip.com.au> |
| To | Vladimir Ignatov <kmisoft@gmail.com> |
| Cc | python-list@python.org |
| Subject | Re: looking for standard/builtin dict-like data object |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii; format=flowed |
| Content-Disposition | inline |
| In-Reply-To | <CAK_Erkid-bWZpUhmLsBmRvDPW2iyQG-RHLRq4LrgJozoC6tMvQ@mail.gmail.com> |
| User-Agent | Mutt/1.5.23 (2014-03-12) |
| References | <CAK_Erkid-bWZpUhmLsBmRvDPW2iyQG-RHLRq4LrgJozoC6tMvQ@mail.gmail.com> |
| 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.62.1439264463.3627.python-list@python.org> (permalink) |
| Lines | 47 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1439264463 news.xs4all.nl 2856 [2001:888:2000:d::a6]:54898 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:95242 |
Show key headers only | View raw
On 10Aug2015 23:22, Vladimir Ignatov <kmisoft@gmail.com> wrote:
>In my code I often use my own home-brewed object for passing bunch of
>data between functions. Something like:
>
>class Data(object):
> def __init__ (self, **kwargs):
> self.__dict__ = kwargs
>....
>
>return Data(attr1=..., attr2=..., attr3=...)
>
>Logically it works like plain dictionary but with nice result.attrX
>syntax on client side (instead of resut['attrX']). Overall I am
>pretty happy with this approach except that I need to drag Data class
>around my projects and import its module in every code producing data.
I've got a base class called "O" like that:
https://pypi.python.org/pypi/cs.obj/
>I am curious if anybody knows similar "dummy" class located in
>standard libraries? I'd be glad to use it instead.
namedtuple initialises and accesses like that:
>>> from collections import namedtuple
>>> Klass = namedtuple('Klass', 'a b c')
>>> o1 = Klass(1,2,3)
>>> o1
O(a=1, b=2, c=3)
>>> o1.b
2
>>> o2 = Klass(a=1,c=3,b=2)
>>> o2
O(a=1, b=2, c=3)
namedtuple makes a factory for making particular flavours.
And the result us a tuple, not a dict.
I also thought the stdlib had some kind of "namespace" class with this kind of
API, but I can't find it now:-(
Cheers,
Cameron Simpson <cs@zip.com.au>
Always code as if the guy who ends up maintaining your code will be a violent
psychopath who knows where you live.
- Martin Golding, DoD #0236, martin@plaza.ds.adp.com
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: looking for standard/builtin dict-like data object Cameron Simpson <cs@zip.com.au> - 2015-08-11 13:40 +1000
csiph-web