I may be asking this in the wrong place but I have a tal page where I want to use python to display only the most recent addition to a folder of files. I can sort the folder and return all the files easily with: return sequence.sort(files, (('bobobase_modification_time', 'cmp', 'desc'),)) How do I return just the most recent one? (I tried sorting and then using return max(files) but that doesn't give me all the properties and I need them for display) Kate
Kate Legere wrote:
I may be asking this in the wrong place but I have a tal page where I want to use python to display only the most recent addition to a folder of files.
I can sort the folder and return all the files easily with: return sequence.sort(files, (('bobobase_modification_time', 'cmp', 'desc'),))
How do I return just the most recent one? (I tried sorting and then using return max(files) but that doesn't give me all the properties and I need them for display)
If it's sorted, you can use a Python slice:: return sequence.sort(files, (('bobobase_modification_time', 'cmp', 'desc'),))[0] The trick is the last three characters. See http://docs.python.org/tut/node5.html --jcc -- "Building Websites with Plone" http://plonebook.packtpub.com/
Am Dienstag, den 31.05.2005, 15:34 -0400 schrieb Kate Legere:
I may be asking this in the wrong place but I have a tal page where I want to use python to display only the most recent addition to a folder of files.
I can sort the folder and return all the files easily with: return sequence.sort(files, (('bobobase_modification_time', 'cmp', 'desc'),))
How do I return just the most recent one? (I tried sorting and then using return max(files) but that doesn't give me all the properties and I need them for display)
Use: return sequence.sort(files, (('bobobase_modification_time', 'cmp','desc'),))[:3] [:3] is a slice operator which returns item0...item2 since you sorted descenting by modification time, the first 3 objects should be the most recent 3. Regards Tino
participants (3)
-
J Cameron Cooper -
Kate Legere -
Tino Wildenhain