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 | |
Fred Drake | 1947991 | 1998-02-13 06:58:54 +0000 | [diff] [blame^] | 10 | \setindexsubitem{(in module code)} |
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 |
| 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"}. |
| 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 |
| 29 | \code{SyntaxError} if the command is a syntax error. |
| 30 | |
| 31 | |
| 32 | \end{funcdesc} |