blob: 877b7a4eb0bb5ab68e1725673e833aa920d397a1 [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
Fred Drakeda452bf1999-01-27 15:48:23 +00009objects. It defines the following function:
Guido van Rossum61c27031997-07-18 21:08:07 +000010
Guido van Rossum61c27031997-07-18 21:08:07 +000011
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
Fred Drakeda452bf1999-01-27 15:48:23 +000022\code{'<input>'}; and \var{symbol} is the optional grammar start
23symbol, which should be either \code{'single'} (the default) or
24\code{'eval'}.
Guido van Rossum61c27031997-07-18 21:08:07 +000025
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
Fred Drakeda452bf1999-01-27 15:48:23 +000029\exception{SyntaxError} if the command is a syntax error.
Guido van Rossum61c27031997-07-18 21:08:07 +000030\end{funcdesc}