Hi all, I have 2 sqlmethods foo and bar then i have a python script ----------------------- x=int(myx) mylist=[] for result in context.foo: mylist.append(result) if x == 2: for result in context.bar: mylist.append(result) return mylist ----------------------- what i want to do is sort this list by a field eg. mylist.sort('fieldname') but obviously the sort function dose not work like that -- -tim zegir
Hi Tim, Tim Zegir wrote:
Hi all,
I have 2 sqlmethods foo and bar
then i have a python script
----------------------- x=int(myx) mylist=[]
for result in context.foo: mylist.append(result) if x == 2: for result in context.bar: mylist.append(result) return mylist -----------------------
what i want to do is sort this list by a field eg. mylist.sort('fieldname') but obviously the sort function dose not work like that
as andreas says -> consult python documentation and/or zope book on sequence.sort() Otoh, why dont you join (union) the data in the database and also sort there? Regards Tino
--On Mittwoch, 21. Januar 2004 16:04 Uhr +1100 Tim Zegir <trzegir@ncable.net.au> wrote:
what i want to do is sort this list by a field eg. mylist.sort('fieldname') but obviously the sort function dose not work like that
The obvisious reason why it does not work is that you have not consulted neither the Python documentation on list.sort() nor Zope sequence.sort() method. Both are documented and explained several times on this list....read or google. -aj
Tim Zegir wrote at 2004-1-21 16:04 +1100:
I have 2 sqlmethods foo and bar
then i have a python script
----------------------- x=int(myx) mylist=[]
for result in context.foo:
Are you sure, this does work? You say above "foo" is an Z SQL Method. A Z SQL Method is not a sequence and your cannot iterated over it. You must apply it to get a sequence as result.
... what i want to do is sort this list by a field eg. mylist.sort('fieldname')
You want to look at the "sequence.sort" documentation... -- Dieter
On Thu, 2004-01-22 at 06:53, Dieter Maurer wrote:
Tim Zegir wrote at 2004-1-21 16:04 +1100:
I have 2 sqlmethods foo and bar
then i have a python script
----------------------- x=int(myx) mylist=[]
for result in context.foo: this should be for result in context.foo(): and yes it does work Are you sure, this does work?
You say above "foo" is an Z SQL Method. A Z SQL Method is not a sequence and your cannot iterated over it. You must apply it to get a sequence as result.
... what i want to do is sort this list by a field eg. mylist.sort('fieldname')
You want to look at the "sequence.sort" documentation... I've tryed google many times searching for sequence.sort and while returning results I cant seem to find anything explaining how to use it.
Any by trial and error i have come up with the following. --------- sequence.sort(mylist, ('name')) --------- this does not produce an error but also does not sort the list. btw if i try sequence.sort(mylist, ('name', 'description')) i get "sort option must contains no more than 2 fields" thanks for the help so far -- -tim zegir
Tim Zegir wrote at 2004-1-22 09:37 +1100:
...
You want to look at the "sequence.sort" documentation... I've tryed google many times searching for sequence.sort and while returning results I cant seem to find anything explaining how to use it.
"sequence.sort" is documented (e.g.) in the embedded Zope Online help system. I expect that you find documentation in the Zope Book (2.6 edition, appendix), too. -- Dieter
participants (4)
-
Andreas Jung -
Dieter Maurer -
Tim Zegir -
Tino Wildenhain