blob: a0b58a5d3537fe061eef682d740cb82148ec089f [file] [log] [blame]
Fred Drakeb742a421999-06-23 13:33:40 +00001% LaTeXed from excellent doc-string.
2\section{\module{codeop} ---
3 Compile Python code}
4
5\declaremodule{standard}{codeop}
6\sectionauthor{Moshe Zadka}{mzadka@geocities.com}
7\modulesynopsis{Compile (possibly incomplete) Python code.}
8
9The \module{codeop} module provides a function to compile Python code
10with hints on whether it certainly complete, possible complete or
11definitely incomplete. This is used by the \refmodule{code} module
12and should not normally be used directly.
13
14The \module{codeop} module defines the following function:
15
16\begin{funcdesc}{compile_command}
17 {source\optional{, filename\optional{, symbol}}}
18
19Try to compile \var{source}, which should be a string of Python
20code. Return a code object if \var{source} is valid
21Python code. In that case, the filename attribute of the code object
22will be \var{filename}, which defaults to \code{'<input>'}.
23
24Return \code{None} if \var{source} is \emph{not} valid Python
25code, but is a prefix of valid Python code.
26
27Raise an exception if there is a problem with \var{source}:
28\begin{itemize}
29 \item \exception{SyntaxError}
30 if there is invalid Python syntax.
31 \item \exception{OverflowError}
32 if there is an invalid numeric constant.
33\end{itemize}
34
35The \var{symbol} argument means whether to compile it as a statement
36(\code{'single'}, the default) or as an expression (\code{'eval'}).
37
38\strong{Caveat:}
39It is possible (but not likely) that the parser stops parsing
40with a successful outcome before reaching the end of the source;
41in this case, trailing symbols may be ignored instead of causing an
42error. For example, a backslash followed by two newlines may be
43followed by arbitrary garbage. This will be fixed once the API
44for the parser is better.
45\end{funcdesc}