x = 30
def out():
x = 50
def inner():
print x
print locals()
return inner
out()() # print locals() output {'x': 50}
但是当我使用exec
时,print locals()
的输出为空
x =30
def out():
x = 50
def inner():
print x
print locals()
exec 'print x' in globals(), locals()
return inner
out()() # print locals() ouput {}
exec
对locals()
的输出有任何副作用吗?