You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
deffoo():
x=1exec("x = 42")
print(x) # Prints 1 (exec has no effect)
I know there are a variety of issues surrounding exec(), function
bodies, and other matters. Just wondering if this sort of thing is now
forbidden or not.
It is "valid" Python 3 and the lack of an effect on the local is correct.
From Python 3 on, "exec" is a function and therefore lacks the special
magic properties it had in Python 2 that made it possible execute the
code "as if it just was written there".
In effect, what exec() modifies here is similar to what locals()
returns: a mere copy of the local namespace.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: