Mercurial > cpython-lru_cache-weakref
annotate Doc/lib/libcode.tex @ 17581:c1937faabb23 2.1
Added support for optional explanation parameter to the \versionadded
macro.
Refactored do_cmd_versionadded() and do_cmd_versionchanged() to do most
of the work in a helper function, with the do_cmd_*() wrappers just supplying
a portion of the replacement text.
| author | Fred Drake <fdrake@acm.org> |
|---|---|
| date | Wed, 18 Apr 2001 17:29:14 +0000 |
| parents | 07a2dc1b72ae |
| children | 17b2afba7a6f |
| rev | line source |
|---|---|
| 8918 | 1 \section{\module{code} --- |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
2 Interpreter base classes} |
|
8716
760dcf197048
Adjusted to use the new module synopsis support macros.
Fred Drake <fdrake@acm.org>
parents:
7877
diff
changeset
|
3 \declaremodule{standard}{code} |
|
760dcf197048
Adjusted to use the new module synopsis support macros.
Fred Drake <fdrake@acm.org>
parents:
7877
diff
changeset
|
4 |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
5 \modulesynopsis{Base classes for interactive Python interpreters.} |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
6 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
7 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
8 The \code{code} module provides facilities to implement |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
9 read-eval-print loops in Python. Two classes and convenience |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
10 functions are included which can be used to build applications which |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
11 provide an interactive interpreter prompt. |
|
8716
760dcf197048
Adjusted to use the new module synopsis support macros.
Fred Drake <fdrake@acm.org>
parents:
7877
diff
changeset
|
12 |
|
5842
35b14d78c61d
added code.py; codehack.py is obsolete
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
14 \begin{classdesc}{InteractiveInterpreter}{\optional{locals}} |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
15 This class deals with parsing and interpreter state (the user's |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
16 namespace); it does not deal with input buffering or prompting or |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
17 input file naming (the filename is always passed in explicitly). |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
18 The optional \var{locals} argument specifies the dictionary in |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
19 which code will be executed; it defaults to a newly created |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
20 dictionary with key \code{'__name__'} set to \code{'__console__'} |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
21 and key \code{'__doc__'} set to \code{None}. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
22 \end{classdesc} |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
23 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
24 \begin{classdesc}{InteractiveConsole}{\optional{locals\optional{, filename}}} |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
25 Closely emulate the behavior of the interactive Python interpreter. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
26 This class builds on \class{InteractiveInterpreter} and adds |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
27 prompting using the familiar \code{sys.ps1} and \code{sys.ps2}, and |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
28 input buffering. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
29 \end{classdesc} |
|
5842
35b14d78c61d
added code.py; codehack.py is obsolete
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
30 |
|
35b14d78c61d
added code.py; codehack.py is obsolete
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
31 |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
32 \begin{funcdesc}{interact}{\optional{banner\optional{, |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
33 readfunc\optional{, local}}}} |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
34 Convenience function to run a read-eval-print loop. This creates a |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
35 new instance of \class{InteractiveConsole} and sets \var{readfunc} |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
36 to be used as the \method{raw_input()} method, if provided. If |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
37 \var{local} is provided, it is passed to the |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
38 \class{InteractiveConsole} constructor for use as the default |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
39 namespace for the interpreter loop. The \method{interact()} method |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
40 of the instance is then run with \var{banner} passed as the banner |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
41 to use, if provided. The console object is discarded after use. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
42 \end{funcdesc} |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
43 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
44 \begin{funcdesc}{compile_command}{source\optional{, |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
45 filename\optional{, symbol}}} |
|
5842
35b14d78c61d
added code.py; codehack.py is obsolete
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
46 This function is useful for programs that want to emulate Python's |
|
35b14d78c61d
added code.py; codehack.py is obsolete
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
47 interpreter main loop (a.k.a. the read-eval-print loop). The tricky |
|
35b14d78c61d
added code.py; codehack.py is obsolete
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
48 part is to determine when the user has entered an incomplete command |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
49 that can be completed by entering more text (as opposed to a |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
50 complete command or a syntax error). This function |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
51 \emph{almost} always makes the same decision as the real interpreter |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
52 main loop. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
53 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
54 \var{source} is the source string; \var{filename} is the optional |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
55 filename from which source was read, defaulting to \code{'<input>'}; |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
56 and \var{symbol} is the optional grammar start symbol, which should |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
57 be either \code{'single'} (the default) or \code{'eval'}. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
58 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
59 Returns a code object (the same as \code{compile(\var{source}, |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
60 \var{filename}, \var{symbol})}) if the command is complete and |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
61 valid; \code{None} if the command is incomplete; raises |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
62 \exception{SyntaxError} if the command is complete and contains a |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
63 syntax error, or raises \exception{OverflowError} if the command |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
64 includes a numeric constant which exceeds the range of the |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
65 appropriate numeric type. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
66 \end{funcdesc} |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
67 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
68 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
69 \subsection{Interactive Interpreter Objects |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
70 \label{interpreter-objects}} |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
71 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
72 \begin{methoddesc}{runsource}{source\optional{, filename\optional{, symbol}}} |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
73 Compile and run some source in the interpreter. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
74 Arguments are the same as for \function{compile_command()}; the |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
75 default for \var{filename} is \code{'<input>'}, and for |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
76 \var{symbol} is \code{'single'}. One several things can happen: |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
77 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
78 \begin{itemize} |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
79 \item |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
80 The input is incorrect; \function{compile_command()} raised an |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
81 exception (\exception{SyntaxError} or \exception{OverflowError}). A |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
82 syntax traceback will be printed by calling the |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
83 \method{showsyntaxerror()} method. \method{runsource()} returns |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
84 \code{0}. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
85 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
86 \item |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
87 The input is incomplete, and more input is required; |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
88 \function{compile_command()} returned \code{None}. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
89 \method{runsource()} returns \code{1}. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
90 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
91 \item |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
92 The input is complete; \function{compile_command()} returned a code |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
93 object. The code is executed by calling the \method{runcode()} (which |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
94 also handles run-time exceptions, except for \exception{SystemExit}). |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
95 \method{runsource()} returns \code{0}. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
96 \end{itemize} |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
97 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
98 The return value can be used to decide whether to use |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
99 \code{sys.ps1} or \code{sys.ps2} to prompt the next line. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
100 \end{methoddesc} |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
101 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
102 \begin{methoddesc}{runcode}{code} |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
103 Execute a code object. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
104 When an exception occurs, \method{showtraceback()} is called to |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
105 display a traceback. All exceptions are caught except |
|
13625
fdfd1049f36e
Rob W. W. Hooft's spelling fixes for the Library Reference. I hope
Thomas Wouters <thomas@python.org>
parents:
12223
diff
changeset
|
106 \exception{SystemExit}, which is allowed to propagate. |
|
5842
35b14d78c61d
added code.py; codehack.py is obsolete
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
107 |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
108 A note about \exception{KeyboardInterrupt}: this exception may occur |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
109 elsewhere in this code, and may not always be caught. The caller |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
110 should be prepared to deal with it. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
111 \end{methoddesc} |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
112 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
113 \begin{methoddesc}{showsyntaxerror}{\optional{filename}} |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
114 Display the syntax error that just occurred. This does not display |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
115 a stack trace because there isn't one for syntax errors. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
116 If \var{filename} is given, it is stuffed into the exception instead |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
117 of the default filename provided by Python's parser, because it |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
118 always uses \code{'<string>'} when reading from a string. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
119 The output is written by the \method{write()} method. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
120 \end{methoddesc} |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
121 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
122 \begin{methoddesc}{showtraceback}{} |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
123 Display the exception that just occurred. We remove the first stack |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
124 item because it is within the interpreter object implementation. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
125 The output is written by the \method{write()} method. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
126 \end{methoddesc} |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
127 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
128 \begin{methoddesc}{write}{data} |
|
14561
07a2dc1b72ae
Denis S. Otkidach <ods@users.sourceforge.net>:
Fred Drake <fdrake@acm.org>
parents:
13625
diff
changeset
|
129 Write a string to the standard error stream (\code{sys.stderr}). |
|
07a2dc1b72ae
Denis S. Otkidach <ods@users.sourceforge.net>:
Fred Drake <fdrake@acm.org>
parents:
13625
diff
changeset
|
130 Derived classes should override this to provide the appropriate output |
|
07a2dc1b72ae
Denis S. Otkidach <ods@users.sourceforge.net>:
Fred Drake <fdrake@acm.org>
parents:
13625
diff
changeset
|
131 handling as needed. |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
132 \end{methoddesc} |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
133 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
134 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
135 \subsection{Interactive Console Objects |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
136 \label{console-objects}} |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
137 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
138 The \class{InteractiveConsole} class is a subclass of |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
139 \class{InteractiveInterpreter}, and so offers all the methods of the |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
140 interpreter objects as well as the following additions. |
|
5842
35b14d78c61d
added code.py; codehack.py is obsolete
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
141 |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
142 \begin{methoddesc}{interact}{\optional{banner}} |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
143 Closely emulate the interactive Python console. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
144 The optional banner argument specify the banner to print before the |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
145 first interaction; by default it prints a banner similar to the one |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
146 printed by the standard Python interpreter, followed by the class |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
147 name of the console object in parentheses (so as not to confuse this |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
148 with the real interpreter -- since it's so close!). |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
149 \end{methoddesc} |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
150 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
151 \begin{methoddesc}{push}{line} |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
152 Push a line of source text to the interpreter. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
153 The line should not have a trailing newline; it may have internal |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
154 newlines. The line is appended to a buffer and the interpreter's |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
155 \method{runsource()} method is called with the concatenated contents |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
156 of the buffer as source. If this indicates that the command was |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
157 executed or invalid, the buffer is reset; otherwise, the command is |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
158 incomplete, and the buffer is left as it was after the line was |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
159 appended. The return value is \code{1} if more input is required, |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
160 \code{0} if the line was dealt with in some way (this is the same as |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
161 \method{runsource()}). |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
162 \end{methoddesc} |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
163 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
164 \begin{methoddesc}{resetbuffer}{} |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
165 Remove any unhandled source text from the input buffer. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
166 \end{methoddesc} |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
167 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
168 \begin{methoddesc}{raw_input}{\optional{prompt}} |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
169 Write a prompt and read a line. The returned line does not include |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
170 the trailing newline. When the user enters the \EOF{} key sequence, |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
171 \exception{EOFError} is raised. The base implementation uses the |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
172 built-in function \function{raw_input()}; a subclass may replace this |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
173 with a different implementation. |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
9963
diff
changeset
|
174 \end{methoddesc} |
