<!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>8.1 Complete Python programs</TITLE>
<META NAME="description" CONTENT="8.1 Complete Python programs">
<META NAME="keywords" CONTENT="ref">
<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="ref.css">
<LINK REL="next" HREF="file-input.html">
<LINK REL="previous" HREF="top-level.html">
<LINK REL="up" HREF="top-level.html">
<LINK REL="next" HREF="file-input.html">
</HEAD>
<BODY bgcolor="#ffffff">
<div class=navigation>
<table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="file-input.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="top-level.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="top-level.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 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="file-input.html">8.2 File input</A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="top-level.html">8. Top-level components</A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="top-level.html">8. Top-level components</A></span>
<br><hr></div>
<!--End of Navigation Panel-->

<H1><A NAME="SECTION0010100000000000000000"></A>
<a name="l2h-722"></a>
<BR>
8.1 Complete Python programs
</H1>

<P>
While a language specification need not prescribe how the language
interpreter is invoked, it is useful to have a notion of a complete
Python program.  A complete Python program is executed in a minimally
initialized environment: all built-in and standard modules are
available, but none have been initialized, except for <tt class=module>sys</tt>
(various system services), <tt class=module>__builtin__</tt> (built-in functions,
exceptions and <tt>None</tt>) and <tt class=module>__main__</tt>.  The latter is used
to provide the local and global namespace for execution of the
complete program.
<a name="l2h-723"></a>
<a name="l2h-724"></a>
<a name="l2h-725"></a>

<P>
The syntax for a complete Python program is that for file input,
described in the next section.

<P>
The interpreter may also be invoked in interactive mode; in this case,
it does not read and execute a complete program but reads and executes
one statement (possibly compound) at a time.  The initial environment
is identical to that of a coplete program; each statement is executed
in the namespace of <tt class=module>__main__</tt>.
<a name="l2h-726"></a>
<a name="l2h-727"></a>

<P>
Under Unix, a complete program can be passed to the interpreter in
three forms: with the <B>-c</B> <I>string</I> command line option, as a
file passed as the first command line argument, or as standard input.
If the file or standard input is a tty device, the interpreter enters
interactive mode; otherwise, it executes the file as a complete
program.
<a name="l2h-728"></a>
<a name="l2h-729"></a>
<a name="l2h-730"></a>

<P>
<p>
<div class=navigation><hr><table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="file-input.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="top-level.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="top-level.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 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="file-input.html">8.2 File input</A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="top-level.html">8. Top-level components</A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="top-level.html">8. Top-level components</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>
