mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
note that the return and yield statements cannot be used at the top level in
exec statements; people coming from certain other languages seem to be confused by this on a regular basis
This commit is contained in:
parent
b3dfc0ae5e
commit
b6e1c11004
1 changed files with 6 additions and 1 deletions
|
|
@ -873,7 +873,12 @@ 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.
|
||||
executed. If it is a code object, it is simply executed. In all
|
||||
cases, the code that's executed is expected to be be valid as file
|
||||
input (see section~\ref{file-input}, ``File input''). Be aware that
|
||||
the \keyword{return} and \keyword{yield} statements may not be used
|
||||
outside of function definitions even within the context of code passed
|
||||
to the \keyword{exec} statement.
|
||||
|
||||
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}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue