@@ -20,7 +20,6 @@ \chapter{Simple statements \label{simple}}
20
20
\productioncont {| \token {continue_stmt}}
21
21
\productioncont {| \token {import_stmt}}
22
22
\productioncont {| \token {global_stmt}}
23
- \productioncont {| \token {exec_stmt}}
24
23
\end {productionlist }
25
24
26
25
@@ -809,7 +808,7 @@ \subsection{Future statements \label{future}}
809
808
That is not a future statement; it's an ordinary import statement with
810
809
no special semantics or syntax restrictions.
811
810
812
- Code compiled by an \keyword {exec} statement or calls to the builtin functions
811
+ Code compiled by calls to the builtin functions \function {exec()},
813
812
\function {compile()} and \function {execfile()} that occur in a module
814
813
\module {M} containing a future statement will, by default, use the new
815
814
syntax or semantics associated with the future statement. This can,
@@ -855,64 +854,14 @@ \section{The \keyword{global} statement \label{global}}
855
854
\strong {Programmer's note:}
856
855
the \keyword {global} is a directive to the parser. It
857
856
applies only to code parsed at the same time as the \keyword {global}
858
- statement. In particular, a \keyword {global} statement contained in an
859
- \keyword {exec} statement does not affect the code block \emph { containing }
860
- the \keyword {exec} statement, and code contained in an \keyword {exec}
861
- statement is unaffected by \keyword {global} statements in the code
862
- containing the \keyword {exec} statement . The same applies to the
857
+ statement. In particular, a \keyword {global} statement contained in a
858
+ string or code object supplied to the builtin \function {exec()} function
859
+ does not affect the code block \emph { containing } the function call,
860
+ and code contained in such a string is unaffected by \keyword {global}
861
+ statements in the code containing the function call . The same applies to the
863
862
\function {eval()}, \function {execfile()} and \function {compile()} functions.
864
- \stindex {exec}
863
+ \bifuncindex {exec}
865
864
\bifuncindex {eval}
866
865
\bifuncindex {execfile}
867
866
\bifuncindex {compile}
868
867
869
-
870
- \section {The \keyword {exec} statement \label {exec } }
871
- \stindex {exec}
872
-
873
- \begin {productionlist }
874
- \production {exec_stmt}
875
- {"exec" \token {expression}
876
- ["in" \token {expression} ["," \token {expression}]]}
877
- \end {productionlist }
878
-
879
- This statement supports dynamic execution of Python code. The first
880
- expression should evaluate to either a string, an open file object, or
881
- a code object. If it is a string, the string is parsed as a suite of
882
- Python statements which is then executed (unless a syntax error
883
- occurs). If it is an open file, the file is parsed until \EOF {} and
884
- executed. If it is a code object, it is simply executed. In all
885
- cases, the code that's executed is expected to be valid as file
886
- input (see section~\ref {file-input }, `` File input'' ). Be aware that
887
- the \keyword {return} and \keyword {yield} statements may not be used
888
- outside of function definitions even within the context of code passed
889
- to the \keyword {exec} statement.
890
-
891
- In all cases, if the optional parts are omitted, the code is executed
892
- in the current scope. If only the first expression after \keyword {in}
893
- is specified, it should be a dictionary, which will be used for both
894
- the global and the local variables. If two expressions are given,
895
- they are used for the global and local variables, respectively.
896
- If provided, \var {locals} can be any mapping object.
897
- \versionchanged [formerly \var {locals} was required to be a dictionary]{2.4}
898
-
899
- As a side effect, an implementation may insert additional keys into
900
- the dictionaries given besides those corresponding to variable names
901
- set by the executed code. For example, the current implementation
902
- may add a reference to the dictionary of the built-in module
903
- \module {__builtin__} under the key \code {__builtins__} (!).
904
- \ttindex {__builtins__}
905
- \refbimodindex {__builtin__}
906
-
907
- \strong {Programmer's hints:}
908
- dynamic evaluation of expressions is supported by the built-in
909
- function \function {eval()}. The built-in functions
910
- \function {globals()} and \function {locals()} return the current global
911
- and local dictionary, respectively, which may be useful to pass around
912
- for use by \keyword {exec}.
913
- \bifuncindex {eval}
914
- \bifuncindex {globals}
915
- \bifuncindex {locals}
916
-
917
-
918
-
0 commit comments