Dynamic code execution with exec and eval

suggest change

Syntax

Parameters

Remarks

In exec, if globals is locals (i.e. they refer to the same object), the code is executed as if it is on the module level. If globals and locals are distinct objects, the code is executed as if it were in a class body.

If the globals object is passed in, but doesn’t specify __builtins__ key, then Python built-in functions and names are automatically added to the global scope. To suppress the availability of functions such as print or isinstance in the executed scope, let globals have the key __builtins__ mapped to value None. However, this is not a security feature.

The Python 2 -specific syntax shouldn’t be used; the Python 3 syntax will work in Python 2. Thus the following forms are deprecated:

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents