Hello, I just want to build a sorted list of list = context.objectValues('ExtFile') for file in list: print file.id, file.title return printed or in other words just the equivalent to the following dtml-code <dtml-in expr="objectValues('ExtFile')" sort="id" reverse> <dtml-var id> <dtml-var title> </dtml-in> Any idea to perform this. Kind regards Andreas.
On Fri, Oct 18, 2002 at 10:15:10AM +0200, Andreas Tille wrote:
Hello,
I just want to build a sorted list of
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> hth Jerome Alet
On Fri, Oct 18, 2002 at 10:20:27AM +0200, Jerome Alet wrote:
On Fri, Oct 18, 2002 at 10:15:10AM +0200, Andreas Tille wrote:
Hello,
I just want to build a sorted list of
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. Replace the lambda with a normal function and it should be ok. Jerome Alet
On Fri, 2002-10-18 at 16:24, Jerome Alet wrote:
On Fri, Oct 18, 2002 at 10:20:27AM +0200, Jerome Alet wrote:
On Fri, Oct 18, 2002 at 10:15:10AM +0200, Andreas Tille wrote:
Hello,
I just want to build a sorted list of
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.
Sorry not true lambda isn't forbidden in Scripts. I use lambda in sorts in PythonScripts all the time. Rgds Tim
Replace the lambda with a normal function and it should be ok.
Jerome Alet
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
On Fri, Oct 18, 2002 at 04:29:33PM +0800, Tim Hoffman wrote:
Sorry I think this won't work in a Python Script because IIRC lambda is forbidden there.
Sorry not true lambda isn't forbidden in Scripts.
I use lambda in sorts in PythonScripts all the time.
Thanks for the info. Time for me to answer to all these spam messagess about how to enlarge my penis^H^H^H^H^Hmemory :-) bye, Jerome Alet
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.
Ick, no lambda needed: items = context.objectItems() items.sort() for id, object in items: print id, object return printed sort is *much* faster when you don't use a comparison function as well (though sometimes you do need them). -Casey On Fri, 18 Oct 2002 10:20:27 +0200 Jerome Alet <alet@librelogiciel.com> wrote:
On Fri, Oct 18, 2002 at 10:15:10AM +0200, Andreas Tille wrote:
Hello,
I just want to build a sorted list of
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>
hth
Jerome Alet
On Fri, Oct 18, 2002 at 09:35:47AM -0400, Casey Duncan wrote:
Ick, no lambda needed:
items = context.objectItems() items.sort() for id, object in items: print id, object return printed
sort is *much* faster when you don't use a comparison function as well (though sometimes you do need them).
then you'd have to call reverse() too, because he wanted them in reverse order. bye, Jerome Alet
On Fri, 18 Oct 2002, Jerome Alet wrote:
On Fri, Oct 18, 2002 at 09:35:47AM -0400, Casey Duncan wrote:
Ick, no lambda needed:
items = context.objectItems() items.sort() for id, object in items: print id, object return printed
sort is *much* faster when you don't use a comparison function as well (though sometimes you do need them).
then you'd have to call reverse() too, because he wanted them in reverse order. Thanks to both of you for the further hint
Andreas.
participants (4)
-
Andreas Tille -
Casey Duncan -
Jerome Alet -
Tim Hoffman