看起来您不能在具有子功能的函数中使用exec ...
有人知道为什么这个Python代码不起作用吗?我在test2中的exec处收到错误。另外,我知道exec的风格不好,但是请相信我,出于适当的原因,我正在使用exec。否则我不会使用它。
#!/usr/bin/env python
#
def test1():
exec('print "hi from test1"')
test1()
def test2():
"""Test with a subfunction."""
exec('print "hi from test2"')
def subfunction():
return True
test2()
编辑:我将错误缩小为在子功能中具有功能。它与raise关键字无关
慕桂英546537
慕田峪4524236
慕神8447489
相关分类