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