| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> |
| 5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> |
| 6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> |
| 7 | <link rel="first" href="lib.html" title='Python Library Reference' /> |
| 8 | <link rel='contents' href='contents.html' title="Contents" /> |
| 9 | <link rel='index' href='genindex.html' title='Index' /> |
| 10 | <link rel='last' href='about.html' title='About this document...' /> |
| 11 | <link rel='help' href='about.html' title='About this document...' /> |
| 12 | <link rel="prev" href="interpreter-objects.html" /> |
| 13 | <link rel="parent" href="module-code.html" /> |
| 14 | <link rel="next" href="module-codeop.html" /> |
| 15 | <meta name='aesop' content='information' /> |
| 16 | <title>3.25.2 Interactive Console Objects </title> |
| 17 | </head> |
| 18 | <body> |
| 19 | <DIV CLASS="navigation"> |
| 20 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> |
| 21 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 22 | <tr> |
| 23 | <td class='online-navigation'><a rel="prev" title="3.25.1 Interactive Interpreter Objects" |
| 24 | href="interpreter-objects.html"><img src='../icons/previous.png' |
| 25 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 26 | <td class='online-navigation'><a rel="parent" title="3.25 code " |
| 27 | href="module-code.html"><img src='../icons/up.png' |
| 28 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 29 | <td class='online-navigation'><a rel="next" title="3.26 codeop " |
| 30 | href="module-codeop.html"><img src='../icons/next.png' |
| 31 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 32 | <td align="center" width="100%">Python Library Reference</td> |
| 33 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 34 | href="contents.html"><img src='../icons/contents.png' |
| 35 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 36 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 37 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 38 | <td class='online-navigation'><a rel="index" title="Index" |
| 39 | href="genindex.html"><img src='../icons/index.png' |
| 40 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 41 | </tr></table> |
| 42 | <div class='online-navigation'> |
| 43 | <b class="navlabel">Previous:</b> |
| 44 | <a class="sectref" rel="prev" href="interpreter-objects.html">3.25.1 Interactive Interpreter Objects</A> |
| 45 | <b class="navlabel">Up:</b> |
| 46 | <a class="sectref" rel="parent" href="module-code.html">3.25 code </A> |
| 47 | <b class="navlabel">Next:</b> |
| 48 | <a class="sectref" rel="next" href="module-codeop.html">3.26 codeop </A> |
| 49 | </div> |
| 50 | <hr /></div> |
| 51 | </DIV> |
| 52 | <!--End of Navigation Panel--> |
| 53 | |
| 54 | <H2><A NAME="SECTION0052520000000000000000"></A><A NAME="console-objects"></A> |
| 55 | <BR> |
| 56 | 3.25.2 Interactive Console Objects |
| 57 | |
| 58 | </H2> |
| 59 | |
| 60 | <P> |
| 61 | The <tt class="class">InteractiveConsole</tt> class is a subclass of |
| 62 | <tt class="class">InteractiveInterpreter</tt>, and so offers all the methods of the |
| 63 | interpreter objects as well as the following additions. |
| 64 | |
| 65 | <P> |
| 66 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 67 | <td><nobr><b><tt id='l2h-753' xml:id='l2h-753' class="method">interact</tt></b>(</nobr></td> |
| 68 | <td><var></var><big>[</big><var>banner</var><big>]</big><var></var>)</td></tr></table></dt> |
| 69 | <dd> |
| 70 | Closely emulate the interactive Python console. |
| 71 | The optional banner argument specify the banner to print before the |
| 72 | first interaction; by default it prints a banner similar to the one |
| 73 | printed by the standard Python interpreter, followed by the class |
| 74 | name of the console object in parentheses (so as not to confuse this |
| 75 | with the real interpreter - since it's so close!). |
| 76 | </dl> |
| 77 | |
| 78 | <P> |
| 79 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 80 | <td><nobr><b><tt id='l2h-754' xml:id='l2h-754' class="method">push</tt></b>(</nobr></td> |
| 81 | <td><var>line</var>)</td></tr></table></dt> |
| 82 | <dd> |
| 83 | Push a line of source text to the interpreter. |
| 84 | The line should not have a trailing newline; it may have internal |
| 85 | newlines. The line is appended to a buffer and the interpreter's |
| 86 | <tt class="method">runsource()</tt> method is called with the concatenated contents |
| 87 | of the buffer as source. If this indicates that the command was |
| 88 | executed or invalid, the buffer is reset; otherwise, the command is |
| 89 | incomplete, and the buffer is left as it was after the line was |
| 90 | appended. The return value is <code>True</code> if more input is required, |
| 91 | <code>False</code> if the line was dealt with in some way (this is the same as |
| 92 | <tt class="method">runsource()</tt>). |
| 93 | </dl> |
| 94 | |
| 95 | <P> |
| 96 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 97 | <td><nobr><b><tt id='l2h-755' xml:id='l2h-755' class="method">resetbuffer</tt></b>(</nobr></td> |
| 98 | <td><var></var>)</td></tr></table></dt> |
| 99 | <dd> |
| 100 | Remove any unhandled source text from the input buffer. |
| 101 | </dl> |
| 102 | |
| 103 | <P> |
| 104 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 105 | <td><nobr><b><tt id='l2h-756' xml:id='l2h-756' class="method">raw_input</tt></b>(</nobr></td> |
| 106 | <td><var></var><big>[</big><var>prompt</var><big>]</big><var></var>)</td></tr></table></dt> |
| 107 | <dd> |
| 108 | Write a prompt and read a line. The returned line does not include |
| 109 | the trailing newline. When the user enters the EOF key sequence, |
| 110 | <tt class="exception">EOFError</tt> is raised. The base implementation uses the |
| 111 | built-in function <tt class="function">raw_input()</tt>; a subclass may replace this |
| 112 | with a different implementation. |
| 113 | </dl> |
| 114 | |
| 115 | <DIV CLASS="navigation"> |
| 116 | <div class='online-navigation'> |
| 117 | <p></p><hr /> |
| 118 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 119 | <tr> |
| 120 | <td class='online-navigation'><a rel="prev" title="3.25.1 Interactive Interpreter Objects" |
| 121 | href="interpreter-objects.html"><img src='../icons/previous.png' |
| 122 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 123 | <td class='online-navigation'><a rel="parent" title="3.25 code " |
| 124 | href="module-code.html"><img src='../icons/up.png' |
| 125 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 126 | <td class='online-navigation'><a rel="next" title="3.26 codeop " |
| 127 | href="module-codeop.html"><img src='../icons/next.png' |
| 128 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 129 | <td align="center" width="100%">Python Library Reference</td> |
| 130 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 131 | href="contents.html"><img src='../icons/contents.png' |
| 132 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 133 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 134 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 135 | <td class='online-navigation'><a rel="index" title="Index" |
| 136 | href="genindex.html"><img src='../icons/index.png' |
| 137 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 138 | </tr></table> |
| 139 | <div class='online-navigation'> |
| 140 | <b class="navlabel">Previous:</b> |
| 141 | <a class="sectref" rel="prev" href="interpreter-objects.html">3.25.1 Interactive Interpreter Objects</A> |
| 142 | <b class="navlabel">Up:</b> |
| 143 | <a class="sectref" rel="parent" href="module-code.html">3.25 code </A> |
| 144 | <b class="navlabel">Next:</b> |
| 145 | <a class="sectref" rel="next" href="module-codeop.html">3.26 codeop </A> |
| 146 | </div> |
| 147 | </div> |
| 148 | <hr /> |
| 149 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> |
| 150 | </DIV> |
| 151 | <!--End of Navigation Panel--> |
| 152 | <ADDRESS> |
| 153 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. |
| 154 | </ADDRESS> |
| 155 | </BODY> |
| 156 | </HTML> |