Creating lambda inside a loop
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/2295290/what-do-lambda-function-closures-capture-in-python">What do (lambda) function closures capture in Python?</a><br>
  <a href="http://stackoverflow.com/questions/7514093/lambda-function-dont-closure-the-parameter-in-python">lambda function don&#39;t closure the parameter in Python?</a>  </p>
</blockquote>



<p>I am trying to create lambdas inside a loop that iterates over a list of objects:</p>

<pre><code>lambdas_list = []
for obj in obj_list:
   lambdas_list.append(lambda : obj.some_var)
</code></pre>

<p>Now, if I iterate over the lambdas list and call them like this:</p>

<pre><code>for f in lambdas_list:
    print f()
</code></pre>

<p>I get the same value. That is the value of the last <code>obj</code> in <code>obj_list</code> since that was the last variable in the block of the list iterator. Any ideas fn a good (pythonic) rewrite of the code to make it work?</p>
