Jun-14-2021, 01:27 PM
(Jun-14-2021, 01:22 PM)deanhystad Wrote: I get a name error when running the program. Maybe a difference between Windows and Linux? exec() is obviously creating a new scope and "a" has not been defined outside that scope.
This works:
def test(): exec("global a; a=100") print(a) test()And as expected, this does not.
Output:100
a = 42 def test(): exec("a=100") print(a) test()
Output:42
Thank you very much. It is very useful. It helps me a lot.