Reputation: 88837
When __builtins__
is set and I try to access function globals, I get this error
>>> 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
>>>
Why is that, where I can read more about it? Can I use it to safeguard expression evaluation?
See Question: How safe is expression evaluation using eval?
Upvotes: 1
Views: 2274
Reputation: 882211
Alas, a long-obsolete concept, see the docs -- the original idea was to provide a safe / sandboxed mode, but it just didn't pan out and was abandoned and deprecated since 2.3.
Upvotes: 3