blob: 12728c7faed641037b28ceae2f0898ff0c36dca5 [file] [log] [blame]
Fred Drake3a0351c1998-04-04 07:23:21 +00001\section{Standard Module \module{code}}
Fred Drakeb91e9341998-07-23 17:59:49 +00002\declaremodule{standard}{code}
3
4\modulesynopsis{Code object services.}
5
Guido van Rossum61c27031997-07-18 21:08:07 +00006
7The \code{code} module defines operations pertaining to Python code
8objects.
9
10The \code{code} module defines the following functions:
11
Guido van Rossum61c27031997-07-18 21:08:07 +000012
Fred Drakea3e672b1997-12-29 18:21:37 +000013\begin{funcdesc}{compile_command}{source, \optional{filename\optional{, symbol}}}
Guido van Rossum61c27031997-07-18 21:08:07 +000014This 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}