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 | |
Guido van Rossum | 61c2703 | 1997-07-18 21:08:07 +0000 | [diff] [blame] | 10 | |
Fred Drake | a3e672b | 1997-12-29 18:21:37 +0000 | [diff] [blame] | 11 | \begin{funcdesc}{compile_command}{source, \optional{filename\optional{, symbol}}} |
Guido van Rossum | 61c2703 | 1997-07-18 21:08:07 +0000 | [diff] [blame] | 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. |
| 18 | |
| 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"}. |
| 24 | |
| 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. |
| 29 | |
| 30 | |
| 31 | \end{funcdesc} |