blob: dd62173cdc02f36b7deaf6e5eda4a5bf61f78c31 [file] [log] [blame]
Fred Drake045c7fc1997-12-17 13:47:39 +00001\section{Standard Module \sectcode{code}}
Guido van Rossum61c27031997-07-18 21:08:07 +00002\label{module-code}
3\stmodindex{code}
4
5The \code{code} module defines operations pertaining to Python code
6objects.
7
8The \code{code} module defines the following functions:
9
10\renewcommand{\indexsubitem}{(in module code)}
11
12\begin{funcdesc}{compile_command}{source\,
13\optional{filename\optional{\, symbol}}}
14This function is useful for programs that want to emulate Python's
15interpreter main loop (a.k.a. the read-eval-print loop). The tricky
16part is to determine when the user has entered an incomplete command
17that can be completed by entering more text (as opposed to a complete
18command or a syntax error). This function \emph{almost} always makes
19the same decision as the real interpreter main loop.
20
21Arguments: \var{source} is the source string; \var{filename} is the
22optional filename from which source was read, defaulting to
23\code{"<input>"}; and \var{symbol} is the optional grammar start
24symbol, which should be either \code{"single"} (the default) or
25\code{"eval"}.
26
27Return a code object (the same as \code{compile(\var{source},
28\var{filename}, \var{symbol})}) if the command is complete and valid;
29return \code{None} if the command is incomplete; raise
30\code{SyntaxError} if the command is a syntax error.
31
32
33\end{funcdesc}