Dynamic functions in python
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/12423614/local-variables-in-python-nested-functions">Local variables in Python nested functions</a>  </p>
</blockquote>



<p>Here is my problem, I need to create functions dynamically in python. I have a list in parameter and I need to create a function for each element of this list.</p>

<p>Here is an example :</p>

<pre><code>list_func = []
list_param = ['foo','bar']

for param in list_param:
    def print_func():
        print(param)

    list_func += [print_func]

for func in list_func:
    func()
</code></pre>

<p>with this code the second loop will just print the last parameter. 
Here is the output :</p>

<pre><code>bar
bar
</code></pre>

<p>I need</p>

<pre><code>foo
bar
</code></pre>

<p>Thanks</p>
