Merge pull request #303 from claudejrogers/patch-1

Update "Late Binding Closures" section of gotchas.rst
This commit is contained in:
Kenneth Reitz
2013-08-14 19:18:08 -07:00
+10
View File
@@ -166,6 +166,16 @@ its arguments by using a default arg like so:
def create_multipliers():
return [lambda x, i=i : i * x for i in range(5)]
Alternatively, you can use the functools.partial function:
.. code-block:: python
from functools import partial
from operator import mul
def create_multipliers():
return [partial(mul, i) for i in range(5)]
When the Gotcha Isn't a Gotcha
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~