In memory of the more than 300 thousand Chinese murdered
exec( 字符类型的代码,全局变量,局部变量 )。其中,全局变量和局部变量可以写成字典形式。
举例:
‘‘‘
字符串
exec(字符串,全局变量、局部变量)
‘‘‘
x = 10
expr = """
z = 30
sum = x + y + z
print(sum)
"""
def func():
y = 20
exec(expr)
exec(expr, {‘x‘: 1, ‘y‘: 2})
exec(expr, {‘x‘: 1, ‘y‘: 2}, {‘y‘: 3, ‘z‘: 4})
func()
CSIC_716_20191213【exec内置函数、元类、pymysql模块】
原文:https://www.cnblogs.com/csic716/p/12037040.html