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