Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #29482
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <d@davea.name> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'python,': 0.02; 'attribute': 0.05; 'cpython': 0.05; 'buildbot': 0.07; 'class,': 0.07; 'default.': 0.07; 'defines': 0.07; 'json': 0.07; 'url:node': 0.07; 'python': 0.09; 'dict': 0.09; 'hiding': 0.09; 'hierarchical': 0.09; 'url:github': 0.09; 'cc:addr:python-list': 0.10; 'commit': 0.15; 'attributes.': 0.16; 'dictionaries': 0.16; 'distinction': 0.16; 'keywords.': 0.16; 'python-dev,': 0.16; 'subject:object': 0.16; 'url:buildbot': 0.16; 'wrote:': 0.17; 'tests': 0.18; 'module': 0.19; 'code.': 0.20; 'mostly': 0.20; 'parameters': 0.20; 'proposed': 0.20; 'trying': 0.21; 'fairly': 0.21; 'assuming': 0.22; 'int,': 0.22; 'keys': 0.22; 'object.': 0.22; 'produces': 0.22; 'visible': 0.22; "i'd": 0.22; 'cc:2**0': 0.23; 'work.': 0.23; 'cc:no real name:2**0': 0.24; 'feature': 0.24; 'allows': 0.25; 'tried': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; '(e.g.': 0.27; 'am,': 0.27; 'implemented': 0.27; 'plain': 0.27; 'skip:b 30': 0.27; 'regular': 0.27; 'run': 0.28; 'post': 0.28; 'dictionary': 0.29; 'feature,': 0.29; 'methods.': 0.29; 'proposing': 0.29; 'strings,': 0.29; 'objects': 0.29; 'skip:_ 10': 0.29; 'probably': 0.29; 'class': 0.29; 'this.': 0.29; 'maybe': 0.29; 'code': 0.31; 'could': 0.32; 'certain': 0.33; 'symbol': 0.33; 'guys': 0.33; 'requirements': 0.33; 'list': 0.35; 'adds': 0.35; 'data,': 0.35; 'there': 0.35; 'really': 0.36; 'ability': 0.36; 'url:org': 0.36; 'data.': 0.36; 'others.': 0.36; 'anything': 0.36; 'why': 0.37; 'rather': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'several': 0.39; 'gives': 0.39; 'received:192': 0.39; 'list,': 0.39; 'received:192.168': 0.40; 'your': 0.60; 'provide': 0.62; 'between': 0.63; 'different': 0.63; 'times': 0.63; 'more': 0.63; 'legal': 0.65; 'results': 0.65; 'risk': 0.66; 'talking': 0.66; 'header:Reply-To:1': 0.68; 'wish': 0.70; 'audience': 0.71; 'received:74.208': 0.71; 'reply-to:no real name:2**0': 0.72; 'bench': 0.84; 'optimized,': 0.84; 'slots.': 0.84; 'subject:Using': 0.84; 'comment.': 0.91; 'results,': 0.91; 'browsing': 0.93 |
| Date | Wed, 19 Sep 2012 07:45:38 -0400 |
| From | Dave Angel <d@davea.name> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 |
| MIME-Version | 1.0 |
| To | Pierre Tardy <tardyp@gmail.com> |
| Subject | Re: Using dict as object |
| References | <345da32c-a22b-4025-bb50-794d684885b1@googlegroups.com> |
| In-Reply-To | <345da32c-a22b-4025-bb50-794d684885b1@googlegroups.com> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | 7bit |
| X-Provags-ID | V02:K0:AiGKp/OmygMZBiEpzCWUWhdD6WxOcDs8WztraPrvJW3 ZPdLZXpThT5pyzaeoKuj9rEN382Zespk24BiHCTvyAhhSKzfzf EERiXtN/DEETCW+jk4O6D82pv0SCpoN9EYg6ZLG0yKOppNzKY3 hx2KlBzQNSDlMKQtjLC0mDAZD1TS/MUK8/F8qntrpYjVOyMQCL 5jak4X8hDihdNGX4i4/5npJ1vvws5wngcOhBrPFg5ONF85m+HQ xECc+2STKCWWxp6aQ+W8Fy4t746QGjJBI/qVZxtsRk/BXoweTa +/oYgt2TdL27LNGV2Bo/BXGMxjHS88sKDFIyx+ckVhl6s/ikg= = |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| Reply-To | d@davea.name |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.909.1348055171.27098.python-list@python.org> (permalink) |
| Lines | 60 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1348055171 news.xs4all.nl 6950 [2001:888:2000:d::a6]:47577 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:29482 |
Show key headers only | View raw
On 09/19/2012 06:24 AM, Pierre Tardy wrote: > One thing that is cooler with java-script than in python is that dictionaries and objects are the same thing. It allows browsing of complex hierarchical data syntactically easy. You probably need some different terminology, since a dictionary is already an object. So's an int, or a list, or anything else visible in python. You're trying to blur the distinction between attribute access and access by key (square brackets). > > For manipulating complex jsonable data, one will always prefer writing: > buildrequest.properties.myprop > rather than > brdict['properties']['myprop'] So what you want is to provide a dict-like class which has both a __getitem__ and a __getattribute__, which produces mostly the same results, if the parameters happen to be reasonable and not conflict with other methods. (Similar for *set*, *del*, and __contains__ and maybe others). This has been proposed and discussed and even implemented many times on this list and others. > This ability in JS is well known for its flaws (e.g. http://drupal.org/node/172169#forin ), and I understand why this is not a feature that we want in python by default. I did work on class that adds this feature, and that I wish to use for manipulating my json data. There are many more flaws than just the hiding of certain items because of existing attributes. Additionally, this would only work for items whose keys are strings, and are strings that happen to be legal symbol names and not keywords. If you also support __setitem__ or __delitem__ you run the risk of arbitrary code trashing the code that makes the class work. > The following github pull request to buildbot has tests that defines specification of such a class, and has several commits, which gives several implementation of the same thing. > https://github.com/buildbot/buildbot/pull/525 > > All implementation I tried are much slower than a pure native dict access. > Each implementation have bench results in commit comment. All of them are 20+x slower than plain dict! Assuming you're talking about CPython benchmarks, the dict is highly optimized, C code. And when you provide your own __getitem__ implementation in pure python, there are many attribute accesses, just to make the code work. > I would like to have python guys advices on how one could optimize this. Use C code and slots. > I'd like to eventually post this to python-dev, please tell if this is really not a good idea. > > Regards, > Pierre if you're proposing a new module for the stdlib, one of the (unstated?) requirements is that it be in regular use by a fairly large audience for a while. -- DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Using dict as object Pierre Tardy <tardyp@gmail.com> - 2012-09-19 03:24 -0700 Re: Using dict as object Dave Angel <d@davea.name> - 2012-09-19 07:45 -0400 Re: Using dict as object Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-09-19 15:02 +0200 Re: Using dict as object Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-09-19 14:04 +0000 Re: Using dict as object Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-09-19 23:04 +0000
csiph-web