Fred Drake | 3a0351c | 1998-04-04 07:23:21 +0000 | [diff] [blame] | 1 | \section{Standard Module \module{code}} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 2 | \declaremodule{standard}{code} |
| 3 | |
| 4 | \modulesynopsis{Code object services.} |
| 5 | |
Guido van Rossum | 61c2703 | 1997-07-18 21:08:07 +0000 | [diff] [blame] | 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 | |
Guido van Rossum | 61c2703 | 1997-07-18 21:08:07 +0000 | [diff] [blame] | 12 | |
Fred Drake | a3e672b | 1997-12-29 18:21:37 +0000 | [diff] [blame] | 13 | \begin{funcdesc}{compile_command}{source, \optional{filename\optional{, symbol}}} |
Guido van Rossum | 61c2703 | 1997-07-18 21:08:07 +0000 | [diff] [blame] | 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} |