Python: how to have dynamicly generated function arguments without using an eval
<p>I am trying to setup a system where users can submit an equation to be solved. I have a class, DP, which represents the full parameterization of the problem. A different class, dpsolver, takes a dp object, constructs the matrices, and will solve the problem.</p>

<p>When creating the DP object, one of the attributes is a function reference where the function is like this:</p>

<pre><code>def equation1(r, tx, p, p_prime, k, k_prime, z, z_prime ):
    """ it is assumed all arguments are same sized ndarray or scalar"""
    inv = k_prime - 0.8 * k
    v = np.power(z_prime * inv, 0.75) * (1-tx) - p*tx + p_prime
    return(v)
</code></pre>

<p>r and tx are scalars defined in the DP object. p, p_prime, k, k_prime, z, z_prime are all numpy matrices which are constructed based on other information contained in the instantiation of the DP class. The DP class contains an OrderedDict which has p,k, and z as keys (in that order). p_prime, k_prime, and z_prime are all inferred by solver. My question is, what is the right way to call the equation1 function from solver. I want to that function as simple as possible, so other people can submit equations which can be easily integrated into this system.</p>

<p>I was thinking that using eval could work, or alternatively using lists and then using eval to unpack the list within equation1. What is the best way to do this without using eval? Or will eval be okay in terms of performance?</p>
