3 ms·
Is it possible x is referring to the memory where x had previously been allocated?
by maxk42 15y ago
Is it possible x is referring to the memory where x had previously been allocated?
- dcrosta 15y agoIt turns out that this is not actually as surprising as I had first thought -- del unbinds a variable from the (local) scope. Since exec results in a new Python frame, it is in that frame's scope that x is deleted, not in the outer frame (of the function exec_code_object_and_return_x). I'm in the process of blogging about this and other quirks of exec -- I'll post back here once that's up.
- revelation 15y agoAt least for Python 2.7, you would expect the code run with exec to share the locals and globals with the environment where you called exec from. Thats why the x = x + 1 works, after all.
- dcrosta 15y agoAfter reading through the bug you linked, now I agree with your statement and not with my first comment here. Will the madness never end?
- deleted 15y ago[deleted]