Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #85223
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <travisgriggs@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'python.': 0.02; 'classes,': 0.05; 'plenty': 0.07; 'apis': 0.09; 'arguments': 0.09; 'methods,': 0.09; 'python': 0.11; 'behave': 0.16; 'googling': 0.16; 'i\xe2\x80\x99d': 0.16; 'i\xe2\x80\x99m': 0.16; 'modifier': 0.16; 'objective-c,': 0.16; 'subclasses': 0.16; 'subject:dictionaries': 0.16; 'to:name:python list': 0.16; 'language': 0.16; 'module': 0.19; 'typing': 0.19; 'academic': 0.26; 'received:172.16': 0.29; 'though.': 0.31; 'class': 0.32; 'extend': 0.32; '(e.g.': 0.33; 'guess': 0.33; 'sense': 0.34; 'could': 0.34; 'problem': 0.35; 'problem.': 0.35; 'tool': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; 'done,': 0.36; 'done': 0.36; 'shows': 0.36; 'should': 0.36; 'too': 0.37; 'message-id:@gmail.com': 0.38; 'tired': 0.38; 'to:addr:python-list': 0.38; 'rather': 0.38; 'does': 0.39; 'aside': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'solve': 0.60; 'first': 0.61; 'header:Message-Id:1': 0.63; '8bit%:43': 0.74; 'can\xe2\x80\x99t': 0.84; 'examples.': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:content-type:content-transfer-encoding:subject:message-id:date :to:mime-version; bh=zHeGhPTgy/VL/jtcqTf3NzJxVpDoDiEYJpUnyAOYs0Y=; b=qGUJ98ETcFnuIVfsWrHnF3Wqi1Ye8NP6u0GHS20NlasfiF4RqNCMQr4+cLjo6PGwCx VT7GrShr9rxfamnYEr7MiJGCeu97sykUVDPAkgGe0ZHZP4fw1l8m/kvDwocPKM2AlbFa wBqkLYETG4EDhHO656hmoywo9+ZV/fSj50GINJvAwZVFuFo426rlNoS2uFZtmlzQi0D3 1ExSV53fxxIC2r6kSLqFJjEbNqwTnHGeuakN36DpJ7OUAv+TncAQ7C7oqqNXbkys9DOC hm0P3/V1ZB2iH9eFL4Rb+vgQs08Xs3dV7eKa24VkHJOHxjNnwL5QmntZ0bz3b4Vz+JYD 2DWA== |
| X-Received | by 10.68.136.194 with SMTP id qc2mr14874894pbb.92.1423068643950; Wed, 04 Feb 2015 08:50:43 -0800 (PST) |
| From | Travis Griggs <travisgriggs@gmail.com> |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | quoted-printable |
| Subject | pymongo and attribute dictionaries |
| Date | Wed, 4 Feb 2015 08:50:40 -0800 |
| To | Python List <python-list@python.org> |
| Mime-Version | 1.0 (Mac OS X Mail 8.2 \(2070.6\)) |
| X-Mailer | Apple Mail (2.2070.6) |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| 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.18469.1423068652.18130.python-list@python.org> (permalink) |
| Lines | 31 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1423068652 news.xs4all.nl 2919 [2001:888:2000:d::a6]:52707 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:85223 |
Show key headers only | View raw
I really like pymongo. And I really like Python. But one thing my fingers really get tired of typing is someDoc[‘_’id’] This just does not roll of the fingers well. Too many “reach for modifier keys” in a row. I would rather use someDoc._id Googling shows that I’m not the first to want to do this in the general sense (e.g. http://stackoverflow.com/questions/4984647/accessing-dict-keys-like-an-attribute-in-python). Arguments aside of whether this should or shouldn’t be done, I want to know how I might solve this with Python. Consider it an academic pursuit. The problem I have is not how to do the AttributeDictionary subclass, there are plenty of those examples. The problem is that the pymongo APIs already return dictionaries. In a language (Smalltalk, Objective-C, Ruby) that supports class extensions, that would be my first tool of choice to solve this problem. I’d just extend Dictionary to behave the way I want and be done with it. I can’t do that in Python though. I guess I could make my own module that subclasses the relevant pymongo classes, and do super() calling implementations of all of the relevant methods, coercing the return type. That is a maintenance headache though. What are my options, if any?
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
pymongo and attribute dictionaries Travis Griggs <travisgriggs@gmail.com> - 2015-02-04 08:50 -0800
Re: pymongo and attribute dictionaries Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-02-05 09:38 +1100
Re: pymongo and attribute dictionaries Ian Kelly <ian.g.kelly@gmail.com> - 2015-02-04 17:19 -0700
Re: pymongo and attribute dictionaries Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-02-05 12:58 +1100
Re: pymongo and attribute dictionaries Vito De Tullio <vito.detullio@gmail.com> - 2015-02-05 06:36 +0100
Re: pymongo and attribute dictionaries Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-02-05 16:43 +1100
Re: pymongo and attribute dictionaries Anssi Saari <as@sci.fi> - 2015-02-05 15:27 +0200
Re: pymongo and attribute dictionaries Ian Kelly <ian.g.kelly@gmail.com> - 2015-02-05 14:11 -0700
csiph-web