[Zope] Sequence sorting module from a Python script

2005-04-24 Thread Leticia Larrosa

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
if 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
"

the 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 22, in orderBy

Line 22 
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?

Thanks in advance.

___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


[Zope] Sequence sorting module from a Python script

2005-04-24 Thread Leticia Larrosa


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: SyntaxErrorError Value: sort 
option must contains no more than 2 fields"and Traceback:"
Traceback (innermost last):Module ZPublisher.Publish, line 101, in 
publishModule ZPublisher.mapply, line 88, in mapplyModule 
ZPublisher.Publish, line 39, in call_objectModule 
Shared.DC.Scripts.Bindings, line 306, in __call__Module 
Shared.DC.Scripts.Bindings, line 343, in _bindAndExecModule 
Products.PythonScripts.PythonScript, line 323, in _execModule None, line 
21, in orderBy- - Line 21Module 
DocumentTemplate.sequence.SortEx, line 66, in sortModule 
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.

___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Sequence sorting module from a Python script

2005-04-24 Thread David H




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


___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Sequence sorting module from a Python script

2005-04-24 Thread Andreas Jung

--On Sonntag, 24. April 2005 17:36 Uhr -0400 Leticia Larrosa 
[EMAIL PROTECTED] 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

pgp51rKhSGV4U.pgp
Description: PGP signature
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )