You are not logged in. Your edit will be placed in a queue until it is peer reviewed.
We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.
Required fields*
-
‘i’ will be 10 in each instance of dynamo once the loop has finished. The variable is not rebound each time around the loop. This is one of the big gotchas about using closures in Python (and other similar languages).bobince– bobince2009年02月10日 18:41:23 +00:00Commented Feb 10, 2009 at 18:41
-
Ah, drat. Thanks for the clarification. Is there a technique that will work?Justin Voss– Justin Voss2009年02月10日 23:55:23 +00:00Commented Feb 10, 2009 at 23:55
-
1Justin, for the solution of this gotcha see: stackoverflow.com/questions/233673/lexical-closures-in-python/…Eli Bendersky– Eli Bendersky2009年02月11日 15:47:14 +00:00Commented Feb 11, 2009 at 15:47
lang-py