嵌套函数中的exec语句使locals()为空?

时间:2017-10-02 08:31:22

标签: python python-2.7

第一

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 {}

execlocals()的输出有任何副作用吗?

0 个答案:

没有答案