I\'m looking for a sane approach to dynamically modify a function\'s local namespace, preferably in a way that adds the lea
May be something like that
def foo():
print(x)
foo.__globals__["x"] = "Hello Python"
foo()
unfortunately this does not works in body of function if varible has been defined
def foo(flag):
x = "Hello World"
if flag:
foo.__globals__["x"] = "Hello Python"
print(x)
prints Hello World in both flag is True or False