设置__builtins__
并尝试访问函数全局变量时,出现此错误
>>> def f(): pass
...
>>> f.func_globals
{'f': <function f at 0x00B83270>, '__builtins__': <module '__builtin__' (built-in)>}
>>> __builtins__ = {}
>>> f.func_globals
Traceback (most recent call last):
File "<string>", line 1, in <string>
RuntimeError: restricted attribute
>>>
为什么会这样,我可以在哪里阅读更多相关信息?我可以用它来保护表达评估吗?