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


Groups > comp.lang.python > #85230

Re: pymongo and attribute dictionaries

From Gregory Ewing <greg.ewing@canterbury.ac.nz>
Newsgroups comp.lang.python
Subject Re: pymongo and attribute dictionaries
Date 2015-02-05 09:52 +1300
Message-ID <cjff4hF6n6lU1@mid.individual.net> (permalink)
References <436419A8-6CD1-43DA-AC5E-A2E974AD585E@gmail.com> <CALwzid=W=R3A9nS1ZFUNduR0WRdMnLdu2g9q+E753DSfEUBy8Q@mail.gmail.com> <mailman.18474.1423081408.18130.python-list@python.org>

Show all headers | View raw


Travis Griggs wrote:
> 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...

You could encapsulate some of that in a helper function such as

def docs(source):
    for d in source:
       yield Doc(d)

then your example becomes

for doc in docs(client.db.radios.find({’_id': {’$regex’: ‘^[ABC]'}})):
    pprint(doc)

-- 
Greg

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


Thread

Re: pymongo and attribute dictionaries Travis Griggs <travisgriggs@gmail.com> - 2015-02-04 12:16 -0800
  Re: pymongo and attribute dictionaries Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-02-05 09:52 +1300

csiph-web