Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2029979

Browse filesBrowse files
author
Kenneth Reitz
committed
Merge pull request #303 from claudejrogers/patch-1
Update "Late Binding Closures" section of gotchas.rst
2 parents 5a5be7b + 51a727d commit 2029979
Copy full SHA for 2029979

File tree

Expand file treeCollapse file tree

1 file changed

+10
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+10
-0
lines changed

‎docs/writing/gotchas.rst

Copy file name to clipboardExpand all lines: docs/writing/gotchas.rst
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,16 @@ its arguments by using a default arg like so:
166166
def create_multipliers():
167167
return [lambda x, i=i : i * x for i in range(5)]
168168
169+
Alternatively, you can use the functools.partial function:
170+
171+
.. code-block:: python
172+
173+
from functools import partial
174+
from operator import mul
175+
176+
def create_multipliers():
177+
return [partial(mul, i) for i in range(5)]
178+
169179
When the Gotcha Isn't a Gotcha
170180
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
171181

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.