title: Passing parameterized function handle in Python
body: <p>I have a general function that defines a form of an ODE that I plan to integrate using <a href="http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.integrate.odeint.html" rel="nofollow"><code>scipy.integrate.odeint</code></a>, for example:</p>
  
  <pre><code>def my_ode(K, tau, y, u):
    return K*u/tau - y/tau  # dydt
  </code></pre>
  
  <p>I have several objects in my code that all have dynamics of the form defined in <code>my_ode</code>, but with unique parameters <code>K</code> and <code>tau</code>. I would love to be able to just pass a unique handle to <code>my_ode</code> with those parameters already set when I initialize my objects, so that when I update my objects, all I have to do is something like <code>soln = odeint(my_ode, t, y, u)</code> for some simulation time <code>t</code>.</p>
  
  <p>For example, if I define a class:</p>
  
  <pre><code>class MyThing:
    def __init__(self, ode, y0):
      # I would rather not maintain K and tau in the objects, I just want the ODE with unique parameters here.
      self.ode = ode
      self.y = y0
      self.time = 0.0
  
    def update(self, t, u):
      # I want this to look something like:
      self.y = scipy.integrate.odeint(self.ode, t, self.y, u)
  </code></pre>
  
  <p>Can I do something with Lambdas when I initialize instances of <code>MyThing</code> to basically assign parameters <code>K</code> and <code>tau</code> at initialization and never need to pass them again? I am a bit stuck.</p>