title: Method delegation in python
body: <p>I'm writing a small framework for orchestrating AWS clusters and there are some common hierarchical patterns that appear over and over again. One such pattern is gathering a collection of instances into a bigger object and then delegating some methods down to all the instances directly. So instead of copying and pasting the same boilerplate code over and over again I abstracted it with the following pattern:</p>
  
  <pre><code>def __getattr__(self, item):
      if not item in self._allowed_items:
          raise NonDelegatableItem
  
      def delegator():
          for instance in self.all_instances:
              getattr(instance, item)()
  
      return delegator
  </code></pre>
  
  <p>Is there a better way or pattern for accomplishing the delegation?</p>