[Zope] Re: Sorting objectValues in Python Script

Andreas Tille tillea@rki.de
Fri, 18 Oct 2002 10:32:56 +0200 (CEST)


On Fri, 18 Oct 2002, Jerome Alet wrote:

> > >    list = context.objectValues('ExtFile')
> > >    for file in list:
> > >         print file.id, file.title
> > >    return printed
> >
> > <UNTESTED>
> > list.sort(lambda x,y : cmp(y.getId(), x.getId()))
> > </UNTESTED>
>
> Sorry I think this won't work in a Python Script because IIRC
> lambda is forbidden there.
Hmmm, I have to search my Python intro what lambda is, but it works as
expected:

	list = context.objectValues('ExtFile')
	list.sort(lambda x,y : cmp(y.getId(), x.getId()))

	for file in list:
	    print file.id, file.title

	return printed

is absolutely fine.

> Replace the lambda with a normal function and it should be ok.
Just for the sake of interest: What do you mean with "normal function"?

Many thanks for the very quick answer!!!!

Kind regards

        Andreas.