[Zope] Sequence sorting module from a Python script

David H bluepaul at earthlink.net
Sun Apr 24 18:28:47 EDT 2005


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/zope/attachments/20050424/82ffe7b7/attachment.htm


More information about the Zope mailing list