Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #85231
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <ian.g.kelly@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.117 |
| X-Spam-Level | * |
| X-Spam-Evidence | '*H*': 0.77; '*S*': 0.00; 'api': 0.11; 'python': 0.11; 'def': 0.12; 'changes': 0.15; 'subject:dictionaries': 0.16; 'travis': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'typing': 0.19; 'feb': 0.22; '(or': 0.24; 'academic': 0.26; 'header:In-Reply- To:1': 0.27; 'function': 0.29; 'message-id:@mail.gmail.com': 0.30; 'doc': 0.31; 'evil': 0.31; 'class': 0.32; 'skip:c 30': 0.32; 'skip:_ 10': 0.34; "i'd": 0.34; 'something': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'like,': 0.36; 'same.': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'free': 0.61; '8bit%:10': 0.64; 'map': 0.64; 'strategy': 0.64; 'interest': 0.64; 'relatively': 0.65; 'skip:\xe2 10': 0.65; '8bit%:21': 0.69; '8bit%:43': 0.74; 'inline': 0.74; '2015': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=ZDkDpAm1lRr4ON+jf2eD2vqdZQmDtBXnxsQqQLhLAag=; b=D7piQHjBD1XA/zfMiVF1oSu718gw9enQc7lzAEwuVwWvLcUOMjwkkZrTRaWr9GgiVq 83ikXn+d5F5SXndXdQIBJATCLx7fkqXctUdVpxjQGcBOvQNiNqZgSZsx3OVu4xnN21Cx 5zPcJg00WCFpUkXSEPttBP09c1xQsQnJ6DLfuBz5hXdkcKDzx1tc+VW6yz4kbpdQTazA ppF++oDE1+iqD4csP0c+nKCT5Vy119hrP9/u0aj/0OnPgrqvqMBVk7CYz3CaY7Mu2ovV YjKD275z4PQTsV04m0falySSsqy8u+h3FnsQt0ZXlL7os0GtdcZ6V56GgEtTAnSEAY3h KFmg== |
| X-Received | by 10.194.89.38 with SMTP id bl6mr383810wjb.146.1423083302911; Wed, 04 Feb 2015 12:55:02 -0800 (PST) |
| MIME-Version | 1.0 |
| In-Reply-To | <70CF795C-8494-48CF-A5F8-3D3F8FE3AE95@gmail.com> |
| References | <436419A8-6CD1-43DA-AC5E-A2E974AD585E@gmail.com> <CALwzid=W=R3A9nS1ZFUNduR0WRdMnLdu2g9q+E753DSfEUBy8Q@mail.gmail.com> <70CF795C-8494-48CF-A5F8-3D3F8FE3AE95@gmail.com> |
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | Wed, 4 Feb 2015 13:54:22 -0700 |
| Subject | Re: pymongo and attribute dictionaries |
| To | Python <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| 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.18476.1423083310.18130.python-list@python.org> (permalink) |
| Lines | 38 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1423083310 news.xs4all.nl 2874 [2001:888:2000:d::a6]:43354 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:85231 |
Show key headers only | View raw
On Wed, Feb 4, 2015 at 1:16 PM, Travis Griggs <travisgriggs@gmail.com> wrote:
> Yes, that is clever. So if you wanted to minimize the amount of typing you had to do at all of your pymongo API call sites, what strategy would you use to keep that relatively terse?
>
> Is the following the right approach to take?
>
> class Doc(object):
> def __init__(self, target):
> self.__dict__ = target
>
> and then something like
>
> for doc in client.db.radios.find({’_id': {’$regex’: ‘^[ABC]'}}):
> pprint(doc)
>
> changes to
>
> for doc in ((Doc(d) for d in client.db.radios.find({’_id': {’$regex’: ‘^[ABC]'}})):
> pprint(doc)
>
> Are there other approaches? Feel free to impress me with evil abuses in the interest of academic enrichment...
I'd prefer map (or itertools.imap in Python 2) over the inline
generator in this case:
for doc in map(Doc, client.db.radios.find({’_id': {’$regex’: ‘^[ABC]'}})):
pprint(doc)
Or if you like, a utility function wrapping the same.
def docs(dicts):
return map(Doc, dicts)
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: pymongo and attribute dictionaries Ian Kelly <ian.g.kelly@gmail.com> - 2015-02-04 13:54 -0700 Re: pymongo and attribute dictionaries Rob Gaddi <rgaddi@technologyhighland.invalid> - 2015-02-04 21:28 +0000
csiph-web