Scripting: sorting some results

Hi there!

I’ll use this line in one of my scripts to get a list of all my slaves to further filter based on the jobs they are rendering at that moment:

allslaves = RepositoryUtils.GetSlaveInfoSettings(True)

When I now do a

for slaves in allslaves:

the slaves are not sorted by any plausible logic. Is it possible to sort the ‘allslaves’ by a defined value (machinename or so), so I can get sorted results afterwards?

Maybe that’s a very dumb question, but my Python knowledge is quite limited.

Thanks, Abraham

Abraham,

In many languages, including Python, when sorting objects it’s possible to specify a function, a lambda, or an index on which to base the sorting. There is a nice article on sorting in Python here: wiki.python.org/moin/HowTo/Sorting

Perfect, works like a charm. I tried the .sort() version, but that didn’t work for the object I had. But using sorted() now works fine. Didn’t knew about that.

Thanks, Abraham