[issue45469] lambda issue in for-loop
Christian Heimes
report at bugs.python.org
Thu Oct 14 08:53:20 EDT 2021
Christian Heimes <lists at cheimes.de> added the comment:
You are running in a typical scope issue. The local and global scope of a lambda work differently than you expect. You can work around the issue by making fun a local variable:
for name, fun in namefun:
name2fun[name] = lambda x, fun=fun: fun(x)
----------
nosy: +christian.heimes
resolution: -> not a bug
stage: -> resolved
status: open -> closed
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45469>
_______________________________________
More information about the Python-bugs-list
mailing list