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