Returning a function from a function in Python
<p>I'm writing a function in Python that takes another function as an argument. Something like this:</p>

<pre><code>DoStuffToFunction(myFunction, arg1, arg2, arg3)
</code></pre>

<p>However, I want to construct <code>myFunction</code> based on the return of another function  </p>

<pre><code>MakeFunction(arg1, arg2, arg3).
</code></pre>

<p>So I do something like: </p>

<pre><code>def MakeFunction(arg1, arg2, arg3):
    def retFunction(arg1, arg2):
        return arg3
    return retFunction
</code></pre>

<p>But then, how do I get <code>myFunction</code> from <code>MakeFunction</code>? If I do <code>myFunction = MakeFunction(stuff1, stuff2, stuff3)</code> I get an error. If I call <code>DoStuffToFunction(MakeFunction, etc1, etc2, etc3)</code> I can't define the parameters of <code>MakeFunction</code>. </p>

<p>The idea is that DoStuffToFunction takes a function. This function is a function of two variables that returns some mathematical result of those two variables. For example:
    def someFunction(x, z):
        return x*z</p>

<p>And MakeFunction should let you quickly create these functions without needing to spend time defining the functions. Basically, it's an attempt to let the user use DoStuffToFunction without much programming knowledge or the know-how to make the function needed. </p>

<p>I feel like I'm missing something here, and if anyone could tell me what it is (or just tell me what I should be Googling) I'd appreciate it! </p>

<p>Update: Wow, okay I think I realized what my problem is. I was attempting to use variables that had never been created and expected Python to know what I wanted it to do. It looks like I need to look into tokenizing strings if I want to do what it is that I intended. Thanks guys!</p>
