How to convert this Python 2.7 code to Python 3?
问题 The following code works in Python 2.7, to dynamically inject local variables into a function scope: myvars = {"var": 123} def func(): exec("") locals().update(myvars) print(var) func() # assert "var" not in globals() It's a bit subtle, but the presence of an exec statement indicates to the compiler that the local namespace may be modified. In the reference implementation, it will transform the lookup of the name "locals" from a LOAD_GLOBAL op into a LOAD_NAME op, enabling addition to the