You are making a lot of selects and this may be slow. I suggest
## input
items=[... a list of ids...]
##table
db.define_table('item',Field('name'))
## algorithm
rows=db(db.item.id.belongs(items)).select(db.item.id,db.item.name)
maps=dict([(row.id,row.name) for row in rows])
new_items=[maps[item] for item in items]
and now you only have one query
On Sep 12, 4:02 pm, Chris S <[email protected]> wrote:
> Update:
>
> ----------------
> for idnum in idnumList:
> for row in sqldb(sqldb.item.idnum==idnum).select():
> name=row.name
> Dictionary['Reagents']=list.replace(idnum,name)
> ------------------
>
> Is working ... sort of. Thus far I have it replacing one number in
> the list I'll look at it more later and post the whole solution when I
> figure it out. It should be noted. When working with the Shell to
> test script only one Quarry can be made, any further DB quarry's
> result in an error until you reload the shell!
>
> On Sep 12, 1:12 pm, Chris S <[email protected]> wrote:
>
> > I'm trying to go through a list of dictionary's and replace one of the
> > key's fields (an idnumber) with another field from a table. The code
> > currently looks like:
>
> > --------------
> > regex = re.compile(r'\[(\d+)\,') #Match's my item numbers
> > for Dictionary in DictList:
> > list = Dictionary['Reagents']
> > idnumList = regex.findall(list)
> > ----------------
>
> > This gives me a nice list (idnumList) with id numbers in it. However
> > I can't seem to find a way to take each of these idnumbers, look them
> > up in a table and return a different field (name).
>
> > I've been trying:
>
> > ----------------
> > for idnum in idnumList:
> > item=sqldb(sqldb.item.idnum==idnum.isdigit()).select()
> > Dictionary['Reagents']=list.replace(idnum,item.name)
> > ---------------
>
> > But I'm told item.name isn't a valid field. Am I going about this the
> > right way, can someone point me in the right direction?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---