1

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?

Community
  • 1
  • 1
Anurag Uniyal
  • 85,954
  • 40
  • 175
  • 219

1 Answers1

3

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.

Alex Martelli
  • 854,459
  • 170
  • 1,222
  • 1,395