Guido van Rossum | 61c2703 | 1997-07-18 21:08:07 +0000 | [diff] [blame^] | 1 | % Template for a library manual section. |
| 2 | |
| 3 | \section{Standard module \sectcode{code}} |
| 4 | \label{module-code} |
| 5 | \stmodindex{code} |
| 6 | |
| 7 | The \code{code} module defines operations pertaining to Python code |
| 8 | objects. |
| 9 | |
| 10 | The \code{code} module defines the following functions: |
| 11 | |
| 12 | \renewcommand{\indexsubitem}{(in module code)} |
| 13 | |
| 14 | \begin{funcdesc}{compile_command}{source\, |
| 15 | \optional{filename\optional{\, symbol}}} |
| 16 | This function is useful for programs that want to emulate Python's |
| 17 | interpreter main loop (a.k.a. the read-eval-print loop). The tricky |
| 18 | part is to determine when the user has entered an incomplete command |
| 19 | that can be completed by entering more text (as opposed to a complete |
| 20 | command or a syntax error). This function \emph{almost} always makes |
| 21 | the same decision as the real interpreter main loop. |
| 22 | |
| 23 | Arguments: \var{source} is the source string; \var{filename} is the |
| 24 | optional filename from which source was read, defaulting to |
| 25 | \code{"<input>"}; and \var{symbol} is the optional grammar start |
| 26 | symbol, which should be either \code{"single"} (the default) or |
| 27 | \code{"eval"}. |
| 28 | |
| 29 | Return a code object (the same as \code{compile(\var{source}, |
| 30 | \var{filename}, \var{symbol})}) if the command is complete and valid; |
| 31 | return \code{None} if the command is incomplete; raise |
| 32 | \code{SyntaxError} if the command is a syntax error. |
| 33 | |
| 34 | |
| 35 | \end{funcdesc} |