Turning String into Numerical Equation

Giovanni Bajo noway at sorry.com
Wed Mar 16 11:28:12 CET 2005


Steven Bethard wrote:

>> When __builtin__ is not the standard __builtin__, Python is in
>> restricted execution mode.
>
> Do you know where this is documented?  I looked around, but couldn't
> find anything.


I found some documentation in the reference of the (now disabled) modules for
Restricted Execution (chapter 17 in the Library Reference). Quoting:

"""
The Python run-time determines whether a particular code block is executing in
restricted execution mode based on the identity of the __builtins__ object in
its global variables: if this is (the dictionary of) the standard __builtin__
module, the code is deemed to be unrestricted, else it is deemed to be
restricted.
"""

There are also some hints in the documentation for eval() itself:

"""
If the globals dictionary is present and lacks '__builtins__', the current
globals are copied into globals before expression is parsed. This means that
expression normally has full access to the standard __builtin__ module and
restricted environments are propagated
"""

In fact, the documentation for eval() could be improved to explain the benefits
of setting __builtins__ in the globals.
-- 
Giovanni Bajo





More information about the Python-list mailing list