I am updating a project from python 2.7 to python 3.6.
I have a list comprehension that looks up variables from locals which worked in python 2.7. It only works in python 3.6 when I switch to using globals.
Below is a toy example to illustrate the issue.
The relevant code is:
(A,B,C) = (1,2,3)
myvars = ['A','B','C']
If I execute the following code:
[locals().get(var) for var in myvars]
the return value in python 3.6 is:
[None, None, None]
However, the return value in python 2.7 is:
[1, 2, 3]
If I execute the following code using globals:
[globals().get(var) for var in myvars]
then I get the same result in python 2.7 and 3.6:
[1, 2, 3]
Can anyone explain why the code using locals() no longer works in python 3.6?