]> granicus.if.org Git - python/commitdiff
Added back the description of the exec statement. It appears that I
authorGuido van Rossum <guido@python.org>
Mon, 6 Jul 1998 13:18:39 +0000 (13:18 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 6 Jul 1998 13:18:39 +0000 (13:18 +0000)
accidentally cut it out when removing the access statement!  Added a
paragraph on __builtins__ and other possible manipulations of the key
space of the dictionaries.  Added some index entries.

Doc/ref/ref6.tex

index e05d83c53c5edd27d0a13a4bf1d58d2d1002b69d..80e9a71228e9fb943318ef9ac9e705ebf9602a90 100644 (file)
@@ -509,3 +509,41 @@ containing the \keyword{exec} statement.  The same applies to the
 \bifuncindex{eval}
 \bifuncindex{execfile}
 \bifuncindex{compile}
+
+\section{The {\tt exec} statement} \label{exec}
+\stindex{exec}
+
+\begin{verbatim}
+exec_stmt:    "exec" expression ["in" expression ["," expression]]
+\end{verbatim}
+
+This statement supports dynamic execution of Python code.  The first
+expression should evaluate to either a string, an open file object, or
+a code object.  If it is a string, the string is parsed as a suite of
+Python statements which is then executed (unless a syntax error
+occurs).  If it is an open file, the file is parsed until EOF and
+executed.  If it is a code object, it is simply executed.
+
+In all cases, if the optional parts are omitted, the code is executed
+in the current scope.  If only the first expression after \keyword{in}
+is specified, it should be a dictionary, which will be used for both
+the global and the local variables.  If two expressions are given,
+both must be dictionaries and they are used for the global and local
+variables, respectively.
+
+As a side effect, an implementation may insert additional keys into
+the dictionaries given besides those corresponding to variable names
+set by the executed code.  For example, the current implementation
+may add a reference to the dictionary of the built-in module
+\module{__builtin__} under the key \code{__builtins__} (!).
+\ttindex{__builtins__}
+\refbimodindex{__builtin__}
+
+Hints: dynamic evaluation of expressions is supported by the built-in
+function \function{eval()}.  The built-in functions
+\function{globals()} and \function{locals()} return the current global
+and local dictionary, respectively, which may be useful to pass around
+for use by \keyword{exec}.
+\bifuncindex{eval}
+\bifuncindex{globals}
+\bifuncindex{locals}