如何在用户功能中使用exec? 为什么功能未定义?
def func():
exec('f = lambda x: x + 2')
print(f(100))
if __name__ == "__main__":
func()
Traceback (most recent call last):
File "./playground/playground.py", line 10, in <module>
func()
File "./playground/playground.py", line 7, in func
print(f(100))
NameError: name 'f' is not defined