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 00006a9

Browse filesBrowse files
author
Kenneth Reitz
committed
Merge pull request realpython#267 from simon-weber/binding-clarification
Clarify "late binding" in gotchas
2 parents c7f1da2 + e1b5968 commit 00006a9
Copy full SHA for 00006a9

File tree

Expand file treeCollapse file tree

1 file changed

+4
-3
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+4
-3
lines changed

‎docs/writing/gotchas.rst

Copy file name to clipboardExpand all lines: docs/writing/gotchas.rst
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,12 @@ What Does Happen
128128

129129
Five functions are created, but all of them just multiply ``x`` by 4.
130130

131-
Python's closures are *late binding*. This means that names within closures are
132-
looked up at the time the inner function is *called*.
131+
Python's closures are *late binding*.
132+
This means that the values of variables used in closures are looked
133+
up at the time the inner function is called.
133134

134135
Here, whenever *any* of the returned functions are called, the value of ``i``
135-
is looked up in the surrounding scope at call time, when by then the loop has
136+
is looked up in the surrounding scope at call time. By then, the loop has
136137
completed and ``i`` is left with its final value of 4.
137138

138139
What's particularly nasty about this gotcha is the seemingly prevalent

0 commit comments

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