title: referencing class methods in class lists in Python
body: <p>I am writing a class in Python 2.6.2 that contains a lookup table.   Most cases are simple enough that the table contains data.  Some of the cases are more complex and I want to be able call a function.  However, I'm running into some trouble referencing the function.</p>
  
  <p>Here's some sample code:</p>
  
  <pre><code>class a:
      lut = [1,
             3,
             17,
             [12,34],
             5]
  </code></pre>
  
  <p>Where <code>lut</code> is static, and is expected to be constant as well.</p>
  
  <p>and now I wan to do the following:</p>
  
  <pre><code>class a:
      def spam0(self):
          return (some_calculation_based_on_self)
  
      def spam1(self):
          return (a_different_calculation_based_on_self)
  
      lut = [1,
             3,
             17,
             [12,34],
             5,
             self.spam0
             self.spam1]
  </code></pre>
  
  <p>This doesn't compile because <code>self.spam0</code> and <code>self.spam1</code> are undefined.  I tried using <code>a.spam</code> but that is also undefined. How can I set <code>lut[5]</code> to return a reference to <code>self.spam</code>?</p>
  
  <p><strong>Edit:</strong> This is what I plan to do:</p>
  
  <p>(continuing the definition of <code>class a</code>):
      import inspect</p>
  
  <pre><code># continue to somewhere in the definition of class a
  
  def __init__(self, param):
      self.param = param
  
  def eggs(self):
      tmp = lut[param]
      if (insect.isfunction(tmp)): # if tmp is self.spam()
          return tmp()             # should call it here
      return tmp
  </code></pre>
  
  <p>So I want to either return a simple value or run some extra code, depending on the parameter.</p>
  
  <p><strong>Edit:</strong>  <code>lut</code> doesn't have to be a class property, but the methods <code>spam0</code> and <code>spam1</code> do need to access the class members, so they have to belong to the class.</p>
  
  <p>I'm not sure that this is the best way to do this.  I'm still in the process of working this out.</p>