Pro tip:  do not call your controller function "sorted".

Getting past that, I have a Rows object (call it "rowed") that I've created 
from munching through the results of a select().  (Why?  because for 
presentation reasons, I do an aggregation with custom logic.)  In the past, 
ordering was done by the select and "inherited" by rowed.  Now I want the 
option of sorting rowed by a different field (the aggregated count).  If I 
do 
  rowed.records = sorted(rowed.records,key=lambda r: r.NumAdded)
everything is fine.  But if I do
rowed.sort(lambda r: r["NumAdded"])
or
rowed.records.sort(lambda r: ["NumAdded"])
I don't get what I want.  The first doesn't seem to change the ordering, 
and the second raises heck^W an exception
<type 'exceptions.TypeError'>(<lambda>() takes exactly 1 argument (2 given))

In the ticket, rowed.records looks like 
[<Row {'PostDate': datetime.date(2016, 11, 25), 'funkystr': 
'...xxxxxxxxxxxxxxxxxx', 'id': 26L, 'NumAdded': 31L}>, <Row {'PostDate': 
datetime.date(2017, 1, 2), 'funkystr': 'xxxxxxxxxxxxxxx', 'id': 131L, 
'NumAdded': 15L}>, ....]

and r like
<Set (QuarterMaster.PostDate IS NOT NULL)>

These suggest that my lambda is getting passed something other than what's 
in the curly braces above.  What would be the correct way to write the 
lambda (which would right the ship)?

[OT:  I think Opera mucks up the GG formatting controls; I may edit this in 
FF or Chrome tomorrow]

PS:  thanks again to Anthony for previous help with cmp/key issues.

Dave S
/dps

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to