title: Fudging the line between classes and functions
body: <p>I have a series of functions that serve to classify data. Each function is passed the same input. The goal of this system is to be able to drop in new classification functions at will without having to adjust anything.</p>
  
  <p>To do this, I make use of a <code>classes_in_module</code> function lifted from <a href="https://stackoverflow.com/questions/5520580/how-do-you-get-all-classes-defined-in-a-module-but-not-imported">here</a>. Then, every classifier in one python file will be ran on each input.</p>
  
  <p>However, I am finding that implementing the classifier as either a class or a function is kludgy. Classes mean instantiating and executing, while functions lack clean introspection to allow me to query the name or use inheritance to define common values.</p>
  
  <p>Here is an example. First, the class implementation:</p>
  
  <pre><code>class AbstractClassifier(object):
      @property
      def name(self):
          return self.__class__.__name__
  
  class ClassifierA(AbstractClassifier):
      def __init__(self, data):
          self.data = data
      def run(self):
          return 1
  </code></pre>
  
  <p>This can then be used in this fashion, assuming that <code>classifier_list</code> is the output of <code>classes_in_module</code> on a file containing <code>ClassifierA</code> among others:</p>
  
  <pre><code>result = []
  for classifier in classifier_list:
      c = classifier(data)
      result.append(c.run())
  </code></pre>
  
  <p>However, this seems a bit silly. This class is obviously static, and doesn't really need to maintain its own state, as it is used once and discarded. The classifier is really a function, but then I lose the ability to have a shared <code>name</code> property -- I would have to use the ugly introspection technique <code>sys._getframe().f_code.co_name</code> and replicate that code for each classifier function. And any other shared properties between classifiers would also be lost.</p>
  
  <p>What do you think? Should I just accept this mis-use of classes? Or is there a better way?</p>