[Zope] sort in python script dynamically?

Mauricio Souza Lima mauricio.lima at varig.com
Fri Jan 9 07:50:02 EST 2004


> -----Original Message-----
> From: zope-bounces at zope.org [mailto:zope-bounces at zope.org]On Behalf Of
> Jaroslav Lukesh
> Sent: Friday, January 09, 2004 4:47 AM
> To: Andreas Jung; zope at zope.org
> Subject: Re: [Zope] sort in python script dynamically?
>
> Hi Andreas,
>
> I am not big pythonist, just little beginner and I was think that object
>   language was able to do
>
> 	for i in self.objectItems('Folder').sort()
>
> But it does not. So I was try
>
> ids = self.objectIds('Folder')
> ids = ids.sort()
> for i in ids :
>
> TypeError: object of type 'string' is not callable
>
> But I was get following tip:
>
> a=context.objectItems()
> a.sort(lambda x,y: cmp(x[0],y[0]))
> for i in a:
>
> And that works fine. But I absolutelly does not understand to that. And
> my ideas about object programming was get one big hole.

Look how object oriented is it.

This function does not return the list that has been sorted, instead it only
sorts the list, why this? Because the list is a mutable object, it dont
create another list from the sorted original one, so you dont have the list
A unsorted and list B sorted, only sorted list A.

I hope i could explain why this behavior.

Best Regards

--
Mauricio Souza Lima
Web Developer
VARIG Brasil - GGTI
mauricio.lima at varig.com

> Thanks to all which helps me.
>
> Best Regards,
>
> JL.





More information about the Zope mailing list