⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 interpreter-objects.html

📁 一本很好的python的说明书,适合对python感兴趣的人
💻 HTML
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>3.18.1 Interactive Interpreter Objects </title>
<META NAME="description" CONTENT="3.18.1 Interactive Interpreter Objects ">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="lib.css" tppabs="http://www.python.org/doc/current/lib/lib.css">
<LINK REL="next" href="console-objects.html" tppabs="http://www.python.org/doc/current/lib/console-objects.html">
<LINK REL="previous" href="module-code.html" tppabs="http://www.python.org/doc/current/lib/module-code.html">
<LINK REL="up" href="module-code.html" tppabs="http://www.python.org/doc/current/lib/module-code.html">
<LINK REL="next" href="console-objects.html" tppabs="http://www.python.org/doc/current/lib/console-objects.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-code.html" tppabs="http://www.python.org/doc/current/lib/module-code.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="module-code.html" tppabs="http://www.python.org/doc/current/lib/module-code.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="console-objects.html" tppabs="http://www.python.org/doc/current/lib/console-objects.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
  alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
  alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="module-code.html" tppabs="http://www.python.org/doc/current/lib/module-code.html">3.18 code  </A>
<b class="navlabel">Up:</b> <a class="sectref" href="module-code.html" tppabs="http://www.python.org/doc/current/lib/module-code.html">3.18 code  </A>
<b class="navlabel">Next:</b> <a class="sectref" href="console-objects.html" tppabs="http://www.python.org/doc/current/lib/console-objects.html">3.18.2 Interactive Console Objects</A>
<br><hr></DIV>
<!--End of Navigation Panel-->

<H2>
<BR>
3.18.1 Interactive Interpreter Objects
            
</H2>

<P>
<dl><dt><b><a name='l2h-484'><tt class='method'>runsource</tt></a></b> (<var>source</var><big>[</big><var>, filename</var><big>[</big><var>, symbol</var><big>]</big><big>]</big>)
<dd>
Compile and run some source in the interpreter.
Arguments are the same as for <tt class="function">compile_command()</tt>; the
default for <var>filename</var> is <code>'&lt;input&gt;'</code>, and for
<var>symbol</var> is <code>'single'</code>.  One several things can happen:

<P>

<UL>
<LI>The input is incorrect; <tt class="function">compile_command()</tt> raised an
exception (<tt class="exception">SyntaxError</tt> or <tt class="exception">OverflowError</tt>).  A
syntax traceback will be printed by calling the
<tt class="method">showsyntaxerror()</tt> method.  <tt class="method">runsource()</tt> returns
<code>0</code>.

<P>
</LI>
<LI>The input is incomplete, and more input is required;
<tt class="function">compile_command()</tt> returned <code>None</code>.
<tt class="method">runsource()</tt> returns <code>1</code>.

<P>
</LI>
<LI>The input is complete; <tt class="function">compile_command()</tt> returned a code
object.  The code is executed by calling the <tt class="method">runcode()</tt> (which
also handles run-time exceptions, except for <tt class="exception">SystemExit</tt>).
<tt class="method">runsource()</tt> returns <code>0</code>.
</LI>
</UL>

<P>
The return value can be used to decide whether to use
<code>sys.ps1</code> or <code>sys.ps2</code> to prompt the next line.
</dl>

<P>
<dl><dt><b><a name='l2h-485'><tt class='method'>runcode</tt></a></b> (<var>code</var>)
<dd>
Execute a code object.
When an exception occurs, <tt class="method">showtraceback()</tt> is called to
display a traceback.  All exceptions are caught except
<tt class="exception">SystemExit</tt>, which is allowed to propagate.

<P>
A note about <tt class="exception">KeyboardInterrupt</tt>: this exception may occur
elsewhere in this code, and may not always be caught.  The caller
should be prepared to deal with it.
</dl>

<P>
<dl><dt><b><a name='l2h-486'><tt class='method'>showsyntaxerror</tt></a></b> (<big>[</big><var>filename</var><big>]</big>)
<dd>
Display the syntax error that just occurred.  This does not display
a stack trace because there isn't one for syntax errors.
If <var>filename</var> is given, it is stuffed into the exception instead
of the default filename provided by Python's parser, because it
always uses <code>'&lt;string&gt;'</code> when reading from a string.
The output is written by the <tt class="method">write()</tt> method.
</dl>

<P>
<dl><dt><b><a name='l2h-487'><tt class='method'>showtraceback</tt></a></b> ()
<dd>
Display the exception that just occurred.  We remove the first stack
item because it is within the interpreter object implementation.
The output is written by the <tt class="method">write()</tt> method.
</dl>

<P>
<dl><dt><b><a name='l2h-488'><tt class='method'>write</tt></a></b> (<var>data</var>)
<dd>
Write a string to the standard error stream (<code>sys.stderr</code>).
Derived classes should override this to provide the appropriate output
handling as needed.
</dl>

<P>

<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-code.html" tppabs="http://www.python.org/doc/current/lib/module-code.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="module-code.html" tppabs="http://www.python.org/doc/current/lib/module-code.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="console-objects.html" tppabs="http://www.python.org/doc/current/lib/console-objects.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
  alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
  alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="module-code.html" tppabs="http://www.python.org/doc/current/lib/module-code.html">3.18 code  </A>
<b class="navlabel">Up:</b> <a class="sectref" href="module-code.html" tppabs="http://www.python.org/doc/current/lib/module-code.html">3.18 code  </A>
<b class="navlabel">Next:</b> <a class="sectref" href="console-objects.html" tppabs="http://www.python.org/doc/current/lib/console-objects.html">3.18.2 Interactive Console Objects</A>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>See <i><a href="about.html" tppabs="http://www.python.org/doc/current/lib/about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -