| 1 | \section{\module{code} ---
|
|---|
| 2 | Interpreter base classes}
|
|---|
| 3 | \declaremodule{standard}{code}
|
|---|
| 4 |
|
|---|
| 5 | \modulesynopsis{Base classes for interactive Python interpreters.}
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 | The \code{code} module provides facilities to implement
|
|---|
| 9 | read-eval-print loops in Python. Two classes and convenience
|
|---|
| 10 | functions are included which can be used to build applications which
|
|---|
| 11 | provide an interactive interpreter prompt.
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 | \begin{classdesc}{InteractiveInterpreter}{\optional{locals}}
|
|---|
| 15 | This class deals with parsing and interpreter state (the user's
|
|---|
| 16 | namespace); it does not deal with input buffering or prompting or
|
|---|
| 17 | input file naming (the filename is always passed in explicitly).
|
|---|
| 18 | The optional \var{locals} argument specifies the dictionary in
|
|---|
| 19 | which code will be executed; it defaults to a newly created
|
|---|
| 20 | dictionary with key \code{'__name__'} set to \code{'__console__'}
|
|---|
| 21 | and key \code{'__doc__'} set to \code{None}.
|
|---|
| 22 | \end{classdesc}
|
|---|
| 23 |
|
|---|
| 24 | \begin{classdesc}{InteractiveConsole}{\optional{locals\optional{, filename}}}
|
|---|
| 25 | Closely emulate the behavior of the interactive Python interpreter.
|
|---|
| 26 | This class builds on \class{InteractiveInterpreter} and adds
|
|---|
| 27 | prompting using the familiar \code{sys.ps1} and \code{sys.ps2}, and
|
|---|
| 28 | input buffering.
|
|---|
|
|---|