Yes, but before I do that, I want to clarify something. My first implementation results in a JSON list of objects like so (roughly): [ {field1:'field1val',field2:'field2val'}, {field1:'field1val',field2:'field2val'} ] Your reimplementation results in a JSON list of lists where the first list is the field (column) names like so: [ ['field1', 'field2'], ['field1val', 'field2val'], ['field1val', 'field2val'] ] My implementation is more useful for programming in _javascript_. With your implementation (while more efficient on the wire), requires that we have to unpack the data in client-side _javascript_ which adds an extra step for the developer and, if the user has either IE and/or a slow computer this could add an undesirable delay for large datasets (which was the whole point of my using list comprehensions in the first place). So can I send you a patch redone with my method (JSON list of objects)? -tim mdipierro wrote: where? Can you send me a patch? MassimoOn Dec 29, 9:01 am, Timothy Farrell <tfarr...@swgen.com> wrote:You might want to switch back to list comprehensions. Granted the code is uglier but there are two big reasons. 1) Speed. Seehttp://www.daniweb.com/forums/thread32869.htmlfor more info. You could wrap the inner loop inner workings in a function and still reap massive benefits by not having to call list.append() n^2 times. 2) It's recommended for building lists in Py3k. The results of the above linked test are:[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58] [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58] Profile of evenList1(), check the time consumed by the many append() calls: (ignore time consumed by the profiler itself) 50005 function calls in 0.174 CPU seconds Ordered by: standard name ncalls tottime percall cumtime percall filename:lineno(function) 50000 0.066 0.000 0.066 0.000 :0(append) 1 0.002 0.002 0.002 0.002 :0(range) 1 0.005 0.005 0.005 0.005 :0(setprofile) 1 0.001 0.001 0.168 0.168 <string>:1(<module>) 1 0.100 0.100 0.168 0.168 Script1.py:5(evenList1) 1 0.000 0.000 0.174 0.174 profile:0(evenList1()) 0 0.000 0.000 profile:0(profiler) Profile of evenList2(): (ignore time consumed by the profiler itself) 5 function calls in 0.018 CPU seconds Ordered by: standard name ncalls tottime percall cumtime percall filename:lineno(function) 1 0.002 0.002 0.002 0.002 :0(range) 1 0.000 0.000 0.000 0.000 :0(setprofile) 1 0.001 0.001 0.018 0.018 <string>:1(<module>) 1 0.015 0.015 0.017 0.017 Script1.py:15(evenList2) 1 0.000 0.000 0.018 0.018 profile:0(evenList2()) 0 0.000 0.000 profile:0(profiler) mdipierro wrote:OK. it is in trunk but slightly different. The representation is now independent on the database backend. Massimo On Dec 29, 8:04 am, Timothy Farrell<tfarr...@swgen.com>wrote:Massimo, would it help if I made a bzr branch? Timothy Farrell wrote:I've been using this in my setup (my setup has a few customizations) since the thread linked below. Just to say that it works! -tim vince wrote:http://groups.google.com/group/web2py/browse_thread/thread/8e3e33879974663f/64f76c562366aec4?lnk=gst&q=json#64f76c562366aec4willit be added or we'll have to wait? i think it's hard to avoid all dependency contrib / thirdparty package. as long as it's include i think that's fine. -vince-- Timothy Farrell<tfarr...@swgen.com>Computer Guy Statewide General Insurance Agency (www.swgen.com)-- Timothy Farrell<tfarr...@swgen.com>Computer Guy Statewide General Insurance Agency (www.swgen.com)-- Timothy Farrell<tfarr...@swgen.com>Computer Guy Statewide General Insurance Agency (www.swgen.com) -- Timothy Farrell <tfarr...@swgen.com> Computer Guy Statewide General Insurance Agency (www.swgen.com) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~--- |
- [web2py:14238] sqlrow to json again vince
- [web2py:14245] Re: sqlrow to json again Timothy Farrell
- [web2py:14246] Re: sqlrow to json again Timothy Farrell
- [web2py:14249] Re: sqlrow to json again mdipierro
- [web2py:14251] Re: sqlrow to json again Timothy Farrell
- [web2py:14253] Re: sqlrow to json ag... mdipierro
- [web2py:14255] Re: sqlrow to jso... Timothy Farrell
- [web2py:14260] Re: sqlrow to... mdipierro
- [web2py:14268] Re: sqlrow to... mdipierro
- [web2py:14278] Re: sqlrow to... Timothy Farrell
- [web2py:14301] Re: sqlrow to... mdipierro