How to delegate to many functions from a single function in Python?
<p>I need to run many commands on a system over multiple nodes in Python.  I want each node to run independently so I figured that I would make a class for each node and fill it with methods that are specific to nodes.  But when writing my algorithm to make use of those methods, I find that I have to put every call in a for loop:</p>

<pre><code>class MultipleThings(object):
    def __init__(self, index):
        self.index = index

    def some_function(self):
        print "I am index ", self.index

class CollectionOfThings(object):
    def __init__(self):
        self.list_of_objects = []
        for index in range(5):
            self.list_of_objects.append(MultipleThings(index))

        for thing in self.list_of_objects:     # Yuck!!
            thing.some_function()

main = CollectionOfThings()
</code></pre>

<p>This code works perfectly and gives me 5 print statements.  But it is ugly and tedious.  How can I get rid of "for thing in self.list_of_objects:" and just call self.some_function() once, then perhaps let a decorator do the for loop to all of the thing's that exist in my list of things?</p>

<p>Edit:  I guess you could consider this a "batch" mode?  For example, I want to run "ls -l" on 10 systems, then let each class instance process those commands.  When they are all done, the next command might be to "rm tmp" on all 10 systems, and so on.  Multiprocessing will be needed as well, so that the for loop doesn't block on each node.</p>
