Python Lambda WTF

Status
You're currently viewing only technophile's posts. Click here to go back to viewing the entire thread.
Not open for further replies.

technophile

Ars Legatus Legionis
23,768
kbogert":80o1cww4 said:
WTF? It though the scope of the lambda is a snapshot of wherever it was created.
It is. Where this trips most people up is that it captures the scope, not the values. As you've discovered, this means that updating the value of a variable that is referenced in a closure actually updates the value for the closure as well. As you've also discovered, the workaround is to make a copy of the value locally and use the local instead of the capture. :)
 
Status
You're currently viewing only technophile's posts. Click here to go back to viewing the entire thread.
Not open for further replies.