Oops -- Lib/Test should be Lib/test, of course!
[python/dscho.git] / Doc / lib / libcode.tex
blob023d276a11c235c532a623aa3efdd58bcf820339
1 \section{Standard Module \module{code}}
2 \label{module-code}
3 \stmodindex{code}
5 The \code{code} module defines operations pertaining to Python code
6 objects.
8 The \code{code} module defines the following functions:
11 \begin{funcdesc}{compile_command}{source, \optional{filename\optional{, symbol}}}
12 This function is useful for programs that want to emulate Python's
13 interpreter main loop (a.k.a. the read-eval-print loop). The tricky
14 part is to determine when the user has entered an incomplete command
15 that can be completed by entering more text (as opposed to a complete
16 command or a syntax error). This function \emph{almost} always makes
17 the same decision as the real interpreter main loop.
19 Arguments: \var{source} is the source string; \var{filename} is the
20 optional filename from which source was read, defaulting to
21 \code{"<input>"}; and \var{symbol} is the optional grammar start
22 symbol, which should be either \code{"single"} (the default) or
23 \code{"eval"}.
25 Return a code object (the same as \code{compile(\var{source},
26 \var{filename}, \var{symbol})}) if the command is complete and valid;
27 return \code{None} if the command is incomplete; raise
28 \code{SyntaxError} if the command is a syntax error.
31 \end{funcdesc}