How does exec work with locals?

This issue is somewhat discussed in the Python3 bug list. Ultimately, to get this behavior, you need to do: def foo(): ldict = {} exec(“a=3”,globals(),ldict) a = ldict[‘a’] print(a) And if you check the Python3 documentation on exec, you’ll see the following note: The default locals act as described for function locals() below: modifications to … Read more