summaryrefslogtreecommitdiffstats
path: root/Doc/ref
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1998-07-06 13:18:39 (GMT)
committerGuido van Rossum <guido@python.org>1998-07-06 13:18:39 (GMT)
commit5f574aace94a6fba7406bcde237b43e150806f51 (patch)
tree40169eaf79078726460ab55f40f662ffaa842705 /Doc/ref
parent9f2b5243851146f09fcaadc2dbfa97da329c8417 (diff)
downloadcpython-5f574aace94a6fba7406bcde237b43e150806f51.zip
cpython-5f574aace94a6fba7406bcde237b43e150806f51.tar.gz
cpython-5f574aace94a6fba7406bcde237b43e150806f51.tar.bz2
Added back the description of the exec statement. It appears that I
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.
Diffstat (limited to 'Doc/ref')
-rw-r--r--Doc/ref/ref6.tex38
1 files changed, 38 insertions, 0 deletions
diff --git a/Doc/ref/ref6.tex b/Doc/ref/ref6.tex
index e05d83c..80e9a71 100644
--- a/Doc/ref/ref6.tex
+++ b/Doc/ref/ref6.tex
@@ -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}