Sequence sorting module from a Python script
Hi all: I want to order a sequence using the Sequence sorting module from a Python script. I have the following code: " seq = [['Bruzon', 'CUB'], ['Anand', 'IND'], ['Kasparov', 'RUS']] def test(oneElem, twoElem): if oneElem[0] == twoElem[0]: return 0 elif oneElem[0] > twoElem[0]: return 1 else: return -1 sort_on =(('self', test, 'desc')) return sequence.sort(seq, sort_on) " and i get the error: " Error Type: SyntaxError Error Value: sort option must contains no more than 2 fields " and Traceback: " Traceback (innermost last): Module ZPublisher.Publish, line 101, in publish Module ZPublisher.mapply, line 88, in mapply Module ZPublisher.Publish, line 39, in call_object Module Shared.DC.Scripts.Bindings, line 306, in __call__ Module Shared.DC.Scripts.Bindings, line 343, in _bindAndExec Module Products.PythonScripts.PythonScript, line 323, in _exec Module None, line 21, in orderBy - - Line 21 Module DocumentTemplate.sequence.SortEx, line 66, in sort Module DocumentTemplate.sequence.SortEx, line 161, in make_sortfunctions SyntaxError: sort option must contains no more than 2 fields " what i'm doing wrong? any suggestion? Thanks in advance.
Leticia Larrosa wrote:
Hi all:
I want to order a sequence using the Sequence sorting module from a Python script. I have the following code: " seq = [['Bruzon', 'CUB'], ['Anand', 'IND'], ['Kasparov', 'RUS']] def test(oneElem, twoElem): if oneElem[0] == twoElem[0]: return 0 elif oneElem[0] > twoElem[0]: return 1 else: return -1 sort_on =(('self', test, 'desc')) return sequence.sort(seq, sort_on) " and i get the error: " Error Type: SyntaxError Error
Value: sort option must contains no more than 2 fields Leticia, I tested this using a python script in Zope - and it seems to work. Nice to see someone doing something with Chess and Zope! def test(x,y): if x[0] == y[0]: return 0 elif x[0] > y[0]: return 1 else: return -1 request = container.REQUEST seq = [['Bruzon', 'CUB'], ['Anand', 'IND'], ['Kasparov', 'RUS']] seq.sort(test) print seq David
--On Sonntag, 24. April 2005 17:36 Uhr -0400 Leticia Larrosa <LETICIA@tesla.cujae.edu.cu> wrote:
sort_on =(('self', test, 'desc'))
As documented the 'sort_on_ parameter must be a *sequence* of sorting definitions and a *single* sorting definition. This should work: sort_on =(('self', test, 'desc'),) -aj
Thanks to David and Andreas.! -----Original Message----- From: Andreas Jung <lists@andreas-jung.com> To: Leticia Larrosa <LETICIA@tesla.cujae.edu.cu>, zope@zope.org Date: Mon, 25 Apr 2005 05:30:12 +0200 Subject: Re: [Zope] Sequence sorting module from a Python script
--On Sonntag, 24. April 2005 17:36 Uhr -0400 Leticia Larrosa <LETICIA@tesla.cujae.edu.cu> wrote:
sort_on =(('self', test, 'desc'))
As documented the 'sort_on_ parameter must be a *sequence* of sorting definitions and a *single* sorting definition. This should work:
sort_on =(('self', test, 'desc'),)
-aj
participants (3)
-
Andreas Jung -
David H -
Leticia Larrosa