blob: a2d77fe4f60511560637aace2d91f3f90a632002 [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
Fred Drakea3e672b1997-12-29 18:21:37 +000012\begin{funcdesc}{compile_command}{source, \optional{filename\optional{, symbol}}}
Guido van Rossum61c27031997-07-18 21:08:07 +000013This function is useful for programs that want to emulate Python's
14interpreter main loop (a.k.a. the read-eval-print loop). The tricky
15part is to determine when the user has entered an incomplete command
16that can be completed by entering more text (as opposed to a complete
17command or a syntax error). This function \emph{almost} always makes
18the same decision as the real interpreter main loop.
19
20Arguments: \var{source} is the source string; \var{filename} is the
21optional filename from which source was read, defaulting to
22\code{"<input>"}; and \var{symbol} is the optional grammar start
23symbol, which should be either \code{"single"} (the default) or
24\code{"eval"}.
25
26Return a code object (the same as \code{compile(\var{source},
27\var{filename}, \var{symbol})}) if the command is complete and valid;
28return \code{None} if the command is incomplete; raise
29\code{SyntaxError} if the command is a syntax error.
30
31
32\end{funcdesc}