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