Note, in trunk there is now a new .column method for the Rows object, which 
allows you to extract a single column as a list of values (internally, it 
just does a list comprehension, as in my original answer). So, in this case 
you could do:

nums3 = db(db.Measures).select(orderby=db.Measures.measure_date_time).column
('measure_value')

You can also pass a field object to .column:

nums3 = db(db.Measures).select(orderby=db.Measures.measure_date_time).column
(db.Measures.measure_value)

Also, if you don't pass any argument to .column, it will return the first 
column, which is convenient if your database select returns only a single 
column:

nums3 = db().select(db.Measures.measure_value, orderby=db.Measures.
measure_date_time).column()

Anthony

On Monday, May 26, 2014 1:21:15 PM UTC-4, Anthony wrote:
>
> You can do:
>
> nums3 = [r.measure_value for r in db().select(db.Measures.measure_value)]
>
> The .select() returns a Rows object, which acts like a list of Row objects 
> -- if you want to extract just a single value from each Row object, you 
> have to iterate through the Rows object and pull each value out.
>
> Note, depending on what you are doing, you can instead operate on the Rows 
> object itself (rather than generating a list and then operating on the 
> list). For example, to randomize the order:
>
> import random
> random_rows = db(db.Measures).select().sort(lambda r: random.random())
>
> Anthony
>
> On Monday, May 26, 2014 6:20:07 AM UTC-4, Syd Stewart wrote:
>>
>> Hi
>>
>> What is the simplest way please to select a column of figures (floats and 
>> int) into a list, so I can manipulate the list e.g randomise the order 
>>
>>  nums3 = db(db.Measures).select( db.Measures.measure_value, 
>> orderby=db.Measures.measure_date_time)
>>
>>  meannums= sum(nums3)/float(len(nums3))
>>
>> This calculation of the mean keeps giving me an error
>>
>>   File "/home/sydstewart/web2py/applications/SydOwn/controllers/test.py" 
>> <https://sydstewart.pythonanywhere.com/admin/default/edit/SydOwn/controllers/test.py>,
>>  line 92, in cusum
>>     qnum[i][k] = (nums3[k]) - (meannums)
>> TypeError: unsupported operand type(s) for -: 'Row' and 'int'
>>
>>
>> Thanks
>>
>>
>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to