<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--Converted with LaTeX2HTML 98.2 beta6 (August 14th, 1998)
original version by:  Nikos Drakos, CBLU, University of Leeds
* revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
  Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>2. The Very High Level Layer </TITLE>
<META NAME="description" CONTENT="2. The Very High Level Layer ">
<META NAME="keywords" CONTENT="api">
<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="api.css">
<LINK REL="next" HREF="countingRefs.html">
<LINK REL="previous" HREF="intro.html">
<LINK REL="up" HREF="api.html">
<LINK REL="next" HREF="countingRefs.html">
</HEAD>
<BODY bgcolor="#ffffff">
<div class=navigation>
<table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="countingRefs.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="api.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="embedding.html"><img width=32 height=32 align=bottom border=0 alt="previous"
 src="../icons/previous.gif"></A></td>
<td align=center bgcolor="#99CCFF" width="100%">
 <b class=title>Python/C API Reference Manual</b></td>
<td><A HREF="contents.html"><img width=32 height=32 align=bottom border=0 alt="contents"
 src="../icons/contents.gif"></A></td>
<td><img width=32 height=32 align=bottom border=0 alt=""
 src="../icons/blank.gif"></td>
<td><A HREF="genindex.html"><img width=32 height=32 align=bottom border=0 alt="index"
 src="../icons/index.gif"></A></td>
</tr></table><b class=navlabel>Next:</b> <span class=sectref><A HREF="countingRefs.html">3. Reference Counting</A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="api.html">Python/C API Reference Manual</A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="embedding.html">1.4 Embedding Python</A></span>
<br><hr></div>
<!--End of Navigation Panel-->

<H1><A NAME="SECTION004000000000000000000"></A>
<BR>
2. The Very High Level Layer 
</H1>

<P>
The functions in this chapter will let you execute Python source code
given in a file or a buffer, but they will not let you interact in a
more detailed way with the interpreter.

<P>
<dl><dt>int <b><a name="l2h-11"><tt class=cfunction>PyRun_AnyFile</tt></a></b> (<var>FILE *fp, char *filename</var>)
<dd>
  If <var>fp</var> refers to a file associated with an interactive device
  (console or terminal input or Unix pseudo-terminal), return the
  value of <tt class=cfunction>PyRun_InteractiveLoop()</tt>, otherwise return the
  result of <tt class=cfunction>PyRun_SimpleFile()</tt>.  If <var>filename</var> is
  <tt>NULL</tt>, use <tt>"???"</tt> as the filename.
</dl>

<P>
<dl><dt>int <b><a name="l2h-12"><tt class=cfunction>PyRun_SimpleString</tt></a></b> (<var>char *command</var>)
<dd>
  Executes the Python source code from <var>command</var> in the
  <tt class=module>__main__</tt> module.  If <tt class=module>__main__</tt> does not already
  exist, it is created.  Returns <tt>0</tt> on success or <tt>-1</tt> if
  an exception was raised.  If there was an error, there is no way to
  get the exception information.
</dl>

<P>
<dl><dt>int <b><a name="l2h-13"><tt class=cfunction>PyRun_SimpleFile</tt></a></b> (<var>FILE *fp, char *filename</var>)
<dd>
  Similar to <tt class=cfunction>PyRun_SimpleString()</tt>, but the Python source
  code is read from <var>fp</var> instead of an in-memory string.
  <var>filename</var> should be the name of the file.
</dl>

<P>
<dl><dt>int <b><a name="l2h-14"><tt class=cfunction>PyRun_InteractiveOne</tt></a></b> (<var>FILE *fp, char *filename</var>)
<dd>
</dl>

<P>
<dl><dt>int <b><a name="l2h-15"><tt class=cfunction>PyRun_InteractiveLoop</tt></a></b> (<var>FILE *fp, char *filename</var>)
<dd>
</dl>

<P>
<dl><dt>struct _node* <b><a name="l2h-16"><tt class=cfunction>PyParser_SimpleParseString</tt></a></b> (<var>char *str,
                                                             int start</var>)
<dd>
  Parse Python source code from <var>str</var> using the start token
  <var>start</var>.  The result can be used to create a code object which
  can be evaluated efficiently.  This is useful if a code fragment
  must be evaluated many times.
</dl>

<P>
<dl><dt>struct _node* <b><a name="l2h-17"><tt class=cfunction>PyParser_SimpleParseFile</tt></a></b> (<var>FILE *fp,
                                 char *filename, int start</var>)
<dd>
  Similar to <tt class=cfunction>PyParser_SimpleParseString()</tt>, but the Python
  source code is read from <var>fp</var> instead of an in-memory string.
  <var>filename</var> should be the name of the file.
</dl>

<P>
<dl><dt>PyObject* <b><a name="l2h-18"><tt class=cfunction>PyRun_String</tt></a></b> (<var>char *str, int start,
                                           PyObject *globals,
                                           PyObject *locals</var>)
<dd>
  Execute Python source code from <var>str</var> in the context specified
  by the dictionaries <var>globals</var> and <var>locals</var>.  The parameter
  <var>start</var> specifies the start token that should be used to parse
  the source code.

<P>
Returns the result of executing the code as a Python object, or
  <tt>NULL</tt> if an exception was raised.
</dl>

<P>
<dl><dt>PyObject* <b><a name="l2h-19"><tt class=cfunction>PyRun_File</tt></a></b> (<var>FILE *fp, char *filename,
                                         int start, PyObject *globals,
                                         PyObject *locals</var>)
<dd>
  Similar to <tt class=cfunction>PyRun_String()</tt>, but the Python source code is 
  read from <var>fp</var> instead of an in-memory string.  <var>filename</var>
  should be the name of the file.
</dl>

<P>
<dl><dt>PyObject* <b><a name="l2h-20"><tt class=cfunction>Py_CompileString</tt></a></b> (<var>char *str, char *filename,
                                               int start</var>)
<dd>
  Parse and compile the Python source code in <var>str</var>, returning the 
  resulting code object.  The start token is given by <var>start</var>;
  this can be used to constrain the code which can be compiled.  The
  filename specified by <var>filename</var> is used to construct the code
  object and may appear in tracebacks or <tt class=exception>SyntaxError</tt>
  exception messages.  This returns <tt>NULL</tt> if the code cannot be
  parsed or compiled.
</dl>

<P>
<p>
<div class=navigation><hr><table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="countingRefs.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="api.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="embedding.html"><img width=32 height=32 align=bottom border=0 alt="previous"
 src="../icons/previous.gif"></A></td>
<td align=center bgcolor="#99CCFF" width="100%">
 <b class=title>Python/C API Reference Manual</b></td>
<td><A HREF="contents.html"><img width=32 height=32 align=bottom border=0 alt="contents"
 src="../icons/contents.gif"></A></td>
<td><img width=32 height=32 align=bottom border=0 alt=""
 src="../icons/blank.gif"></td>
<td><A HREF="genindex.html"><img width=32 height=32 align=bottom border=0 alt="index"
 src="../icons/index.gif"></A></td>
</tr></table><b class=navlabel>Next:</b> <span class=sectref><A HREF="countingRefs.html">3. Reference Counting</A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="api.html">Python/C API Reference Manual</A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="embedding.html">1.4 Embedding Python</A></span>
</div>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>Send comments on this document to <a href="mailto:python-docs@python.org">python-docs@python.org</a>.
</ADDRESS>
</BODY>
</HTML>
