python 之 exec命令

参数1:字符串形式的命令

参数2:全局作用域(字典形式),如果不指定默认使用globals()

参数3:局部作用域(字典形式),如果不指定默认使用locals()

g= {
    'x':1,
    'y':2
}

l = {}

exec("""
global x,m
x=10
m=100
z=3
""",g,l)
print(g)
print(l)
原文地址:https://www.cnblogs.com/stin/p/8514532.html