Sophie

Sophie

distrib > Mandriva > 10.1 > i586 > by-pkgid > ccf83290023404568bb21aa0163b385f > files > 387

python-docs-2.3.4-6.2.101mdk.i586.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.gif" />
<link rel='start' href='../index.html' title='Python Documentation Index' />
<link rel="first" href="lib.html" title='Python Library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<LINK rel="next" href="console-objects.html">
<LINK rel="prev" href="module-code.html">
<LINK rel="parent" href="module-code.html">
<LINK rel="next" href="console-objects.html">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name='aesop' content='information' />
<META name="description" content="Interactive Interpreter Objects ">
<META name="keywords" content="lib">
<META name="resource-type" content="document">
<META name="distribution" content="global">
<title>3.23.1 Interactive Interpreter Objects </title>
</head>
<body>
<DIV CLASS="navigation">
<div id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="3.23 code  " 
  href="module-code.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="3.23 code  " 
  href="module-code.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="3.23.2 Interactive Console Objects" 
  href="console-objects.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents" 
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index" 
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-code.html">3.23 code  </A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-code.html">3.23 code  </A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="console-objects.html">3.23.2 Interactive Console Objects</A>
</div>
<hr /></div>
</DIV>
<!--End of Navigation Panel-->

<H2><A NAME="SECTION0052310000000000000000"><!--x--></A><A NAME="interpreter-objects"><!--z--></A>
<BR>
3.23.1 Interactive Interpreter Objects
            
</H2>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-720' class="method">runsource</tt></b>(</nobr></td>
  <td><var>source</var><big>[</big><var>, filename</var><big>[</big><var>, symbol</var><big>]</big><big>]</big>)</td></tr></table></dt>
<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>False</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>True</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>False</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><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-721' class="method">runcode</tt></b>(</nobr></td>
  <td><var>code</var>)</td></tr></table></dt>
<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><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-722' class="method">showsyntaxerror</tt></b>(</nobr></td>
  <td><big>[</big><var>filename</var><big>]</big>)</td></tr></table></dt>
<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><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-723' class="method">showtraceback</tt></b>(</nobr></td>
  <td>)</td></tr></table></dt>
<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><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-724' class="method">write</tt></b>(</nobr></td>
  <td><var>data</var>)</td></tr></table></dt>
<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">
<div class='online-navigation'><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="3.23 code  " 
  rel="prev" title="3.23 code  " 
  href="module-code.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="3.23 code  " 
  rel="parent" title="3.23 code  " 
  href="module-code.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="3.23.2 Interactive Console Objects" 
  rel="next" title="3.23.2 Interactive Console Objects" 
  href="console-objects.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents" 
  rel="contents" title="Table of Contents" 
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index" 
  rel="index" title="Index" 
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-code.html">3.23 code  </A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-code.html">3.23 code  </A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="console-objects.html">3.23.2 Interactive Console Objects</A>
</div>
</div>
<hr />
<span class="release-info">Release 2.3.4, documentation updated on May 20, 2004.</span>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>