title: Python classes as a collection of functions
body: <p>So here's a very simplified version of the situation I'm currently facing.</p>
  
  <p>I have a class. It does a lot of things, but the primary thing I'm concerned about is that each class member currently accepts a library of static functions and executes a list of commands using that library.</p>
  
  <pre><code>class Example:
      def __init__(self, commands, library, data):
          self.commands = commands
          self.library = library
          self.data = data
  
      def execute(self):
          for command in self.commands:
              result = getattr(self.library, command)(self)
              self.data[result[0]] = result[1]
  </code></pre>
  
  <p>I want to have the capability of switch out these libraries of functions. The current issue is that most of the libraries I am constructing share some core functions, with other functions being different or being overridden. Currently I am using a class to represent these libraries, since the natural inheritance of the class structure handles everything for me.</p>
  
  <pre><code>class Foo:
      static_variable = 4
  
      @staticmethod
      def method_a(foo):
          return 'z', foo.data['x'] + foo.data['y']
  
      @classmethod
      def method_b(cls, foo):
          return 'x', foo.data['x'] * cls.static_variable
  
  
  class FooAlt1(Foo):
      @classmethod
      def method_b(foo):
          return 'y', cls.static_variable
  
  
  class FooAlt2(FooAlt1):
      static_variable = 1   
  </code></pre>
  
  <p>The following is an example of executed code. It's very simple, so it might not get my point across perfectly. The actual code that I am trying to build determines the commands to execute via user input, the data set to run on based on changing environment variables taken from a data base, and then has some logic to assign them to the proper library of functions that will be able to handle everything.</p>
  
  <pre><code>foo1 = Example(commands=['method_b', 'method_a'], library=Foo, data={'x': 3, 'y': 4})
  foo2 = Example(commands=['method_b', 'method_a'], library=FooAlt1, data={'x': 3})
  foo3 = Example(commands=['method_b', 'method_a'], library=FooAlt2, data={'x': 3})
  
  foo1.execute()
  foo2.execute()
  foo3.execute()
  
  print('RESULTS')
  print('foo1: {}'.format(foo1.data))
  print('foo2: {}'.format(foo2.data))
  print('foo3: {}'.format(foo3.data))
  
  # RESULTS
  # foo1: {'z': 16, 'x': 12, 'y': 4}
  # foo2: {'z': 15, 'x': 3, 'y': 12}
  # foo3: {'z': 6, 'x': 3, 'y': 3}
  </code></pre>
  
  <p>This method works well for me, but it feels very un-pythonic, since I'm using classes mostly as a storage container for functions. However, I can't think of a good way to implement this without using classes. The class structure lets me update things easier (I only have to change one function and everything that inherits that function will also be affected), and lets me easily inherit functions if I am making an alternate library that extends or modifies an existing library.</p>
  
  <p>Is there a better way to achieve the result that I want, or am I stuck using classes?</p>