M
Makoto Kuwata
Hi,
Is it possible to run code object with local variables specified?
I'm trying the following code but not work:
def fn():
x = 1
y = 2
localvars = {'x': 0}
exec(fn.func_code, globals(), localvars)
print(localvars)
## what I expected is: {'x': 1, 'y': 2}
## but actual is: {'x': 0}
Python: 2.7.3
OS: MacOS X
Is it possible to run code object with local variables specified?
I'm trying the following code but not work:
def fn():
x = 1
y = 2
localvars = {'x': 0}
exec(fn.func_code, globals(), localvars)
print(localvars)
## what I expected is: {'x': 1, 'y': 2}
## but actual is: {'x': 0}
Python: 2.7.3
OS: MacOS X