1 \section{Standard Module
\module{code
}}
5 The
\code{code
} module defines operations pertaining to Python code
8 The
\code{code
} module defines the following functions:
11 \begin{funcdesc
}{compile_command
}{source,
\optional{filename
\optional{, symbol
}}}
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.
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
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.