This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients
Date 2004-10-17.23:04:50
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
Logged In: YES 
user_id=80475

Please resubmit after boiling this down to the simplest
possible thing that doesn't work according to your
expectations. 

Submitting a whole application and playing the "find the
bug" game is not good use of developer time.  Often, when a
submitter starts taking away the unnecessary pieces and
isolates the issue, they find that there was a bug in their
own code or a bug in their own understanding of how the
language works.

When it comes to lambdas, the most frequent misunderstanding
is knowing that default arguments bind only once as the time
of the lambda declaration and that free variables bind
whenever the resulting function is invoked.  Here's an
example of code that looks similar but behaves differently:
 
def once(x): return x
def twice(x): return 2*x
def thrice(x): return 3*x
funcs = [once, twice, thrice]

flim = [lambda x:funcs[0](x), lambda x:funcs[1](x), lambda
x:funcs[2](x)]
flam = [lambda x:f(x) for f in funcs]

print flim[0](1), flim[1](1), flim[2](1)
print flam[0](1), flam[1](1), flam[2](1)

The difference in output is because nested scopes bind
names, while argument binding binds values.

Hope this helps.  If not, please resubmit with the smallest
case that demonstrates the problem.


History
Date User Action Args
2007-08-23 14:26:46adminlinkissue1048870 messages
2007-08-23 14:26:46admincreate