I am trying to run the following code
def foo():
exec('foo_value = 1')
def foo2():
foo()
print(globals()['foo_value'])
foo2()
But i get the error KeyError: 'foo_value'
Is there a way to be able to use the foo_value
inside the foo2
function, while the foo_value
is created inside another function via the exec()
?