📜  从 exec python 代码示例返回结果

📅  最后修改于: 2022-03-11 14:45:34.840000             🧑  作者: Mango

代码示例1
the_code = '''
a = 1
b = 2
return_me = a + b
'''

loc = {}
exec(the_code, globals(), loc)
return_workaround = loc['return_me']
print(return_workaround)  # 3