代码:
import ast
globalsDict = {}
fAst = ast.FunctionDef(
name="foo",
args=ast.arguments(args=[], vararg=None, kwarg=None, defaults=[]),
body=[], decorator_list=[])
exprAst = ast.Interactive(body=[fAst])
ast.fix_missing_locations(exprAst)
compiled = compile(exprAst, "<foo>", "single")
eval(compiled, globalsDict, globalsDict)
print globalsDict["foo"]
使用 CPython 和 PyPy,我遇到了分段错误。为什么?