Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b6e1c11

Browse files
committed
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
1 parent b3dfc0a commit b6e1c11

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

Doc/ref/ref6.tex

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,12 @@ \section{The \keyword{exec} statement \label{exec}}
873873
a code object. If it is a string, the string is parsed as a suite of
874874
Python statements which is then executed (unless a syntax error
875875
occurs). If it is an open file, the file is parsed until \EOF{} and
876-
executed. If it is a code object, it is simply executed.
876+
executed. If it is a code object, it is simply executed. In all
877+
cases, the code that's executed is expected to be be valid as file
878+
input (see section~\ref{file-input}, ``File input''). Be aware that
879+
the \keyword{return} and \keyword{yield} statements may not be used
880+
outside of function definitions even within the context of code passed
881+
to the \keyword{exec} statement.
877882
878883
In all cases, if the optional parts are omitted, the code is executed
879884
in the current scope. If only the first expression after \keyword{in}

0 commit comments

Comments
 (0)