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