views:

52

answers:

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: http://stackoverflow.com/questions/1994071/how-safe-is-expression-evaluation-using-eval

+3  A: 

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
Thanks, but it is still in action(python 2.5.1) as 'restricted attribute' shows
Anurag Uniyal
It's deprecated, abandoned, not supported, but fossil traces are left hanging around, of course:-(.
Alex Martelli