title: In python, any way to automatically run functions as soon as a class is defined?
body: <p>I am developing a class.  The class-level data it will need is going to be relatively complex.  To save typing and minimize mistakes, I would like to define a good bit of this data through functions.  Also, I would like to make this data available to the user even if they aren't ready to instantiate the class.  So, I wonder, is there a way to get these functions to run automatically as soon as the class is defined?  As an example, I want something like</p>
  
  <pre><code>import numpy as np    
  
  def class foo:
  
          @this_should_run_before_instantiation
          def define_bar:
              bar = np.range(100)
  
         @this_should_also_run_before_init
         def define_something_really complicated:
              bleh = # something that is too complicated for a single line or lambda
  
          def __init__(self):
              # etc.
  </code></pre>
  
  <p>So then the user can do something like</p>
  
  <pre><code>&gt;&gt;&gt;from foopackage import foo
  &gt;&gt;&gt;foo.bar
  array([ 0,  1,  2,  3,  4,  5,  ... #etc.
  &gt;&gt;&gt;foo.bleh
  &lt; whatever bleh is ... &gt;
  </code></pre>