As I've said earlier, the surprise is that the variable is available even though the outer function has exited by now. Global variables never go away (at least unless the module is unloaded, and I've no experience with that.)
Look at my example. The outer function is called multiple times (twice here), and yet the inner function retains not the value of the variable (which is the object), but the instance of the variable. That's apparently accomplished using a 'cell' class, which appears to be a mutable holder for an arbitrary object.
Simon King wrote:
ยทยทยท
...The point I'm trying to make is that people aren't
surprised that the values of global variables are looked up at run time
rather than compile time, so why are they surprised when the variable
happens to be in a nested scope?I hope that helps,
Simon