Re: [web2py] Re: Get result set back as list?
On 8/10/2012 3:58 PM, Vasile Ermicioi wrote: for me that works alist = db(db.auth_user).select().as_list() How funny. I was just making up the name as_list(). Great minds think alike I guess. I was looking for a flat list of field values, but the list comprehension solution is ok I guess. Thanks, Tobiah --
Re: [web2py] Re: Get result set back as list?
On Friday, August 10, 2012 6:58:08 PM UTC-4, Vasile Ermicioi wrote: > > for me that works > > alist = db(db.auth_user).select().as_list() > That returns a list of dictionaries, like [{'myfield': 'value 1'}, {'myfield': 'value 2}]. I assumed he was looking for a list of the individual field values given that it's just a single column of data. Anthony --
[web2py] Re: Get result set back as list?
I use Anthony's method because it returns a true list. as_list() returns a list of dictionaries, and you still have to iterate over the dictionaries in the list to extract the values. On Friday, August 10, 2012 4:34:01 PM UTC-4, Toby Shepard wrote: > > > I'm in a situation where I just want a single column back from > a table. I'd like it as a list so I could just pass it on > to the next function. > > All I can think of is something like: > > temp = [] > > for thing in db(db.mytable).select(db.mytable.myfield): > temp.append(thing) > > return temp > > I was hoping for something like: > > return db(db.mytable).select(db.mytable.myfield).as_list() > > Or something like that. > > As an aside, I have a python dbi that has four central ways to get > data back. I call them: > > atom()scalar as in 'select first from person where > id = 1' > row()dict as in'select * from person' where id > = 1' > column()list as in 'select first from person' > world()list of dict:'select * from person' > > They end up being uite convenient and result in concise syntax. > > Thanks, > > Tobiah > --
Re: [web2py] Re: Get result set back as list?
works for me too. db(db.customers).select(db.customers.name).as_list() On Friday, August 10, 2012 3:58:08 PM UTC-7, Vasile Ermicioi wrote: > > for me that works > > alist = db(db.auth_user).select().as_list() > --
Re: [web2py] Re: Get result set back as list?
for me that works alist = db(db.auth_user).select().as_list() --
[web2py] Re: Get result set back as list?
mylist = [r.myfield for r in db().select(db.mytable.myfield)] Anthony On Friday, August 10, 2012 4:34:01 PM UTC-4, Toby Shepard wrote: > > > I'm in a situation where I just want a single column back from > a table. I'd like it as a list so I could just pass it on > to the next function. > > All I can think of is something like: > > temp = [] > > for thing in db(db.mytable).select(db.mytable.myfield): > temp.append(thing) > > return temp > > I was hoping for something like: > > return db(db.mytable).select(db.mytable.myfield).as_list() > > Or something like that. > > As an aside, I have a python dbi that has four central ways to get > data back. I call them: > > atom()scalar as in 'select first from person where > id = 1' > row()dict as in'select * from person' where id > = 1' > column()list as in 'select first from person' > world()list of dict:'select * from person' > > They end up being uite convenient and result in concise syntax. > > Thanks, > > Tobiah > --