Sophie

Sophie

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

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="module-user.html">
<LINK rel="prev" href="module-new.html">
<LINK rel="parent" href="python.html">
<LINK rel="next" href="module-user.html">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name='aesop' content='information' />
<META name="description" content="site -- Site-specific configuration hook">
<META name="keywords" content="lib">
<META name="resource-type" content="document">
<META name="distribution" content="global">
<title>3.28 site -- Site-specific configuration hook</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.27 new  " 
  href="module-new.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. Python Runtime Services" 
  href="python.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.29 user  " 
  href="module-user.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-new.html">3.27 new  </A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="python.html">3. Python Runtime Services</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-user.html">3.29 user  </A>
</div>
<hr /></div>
</DIV>
<!--End of Navigation Panel-->

<H1><A NAME="SECTION0052800000000000000000">
3.28 <tt class="module">site</tt> --
         Site-specific configuration hook</A>
</H1>

<P>
<A NAME="module-site"><!--z--></A>

<P>
<b>This module is automatically imported during initialization.</b>

<P>
In earlier versions of Python (up to and including 1.5a3), scripts or
modules that needed to use site-specific modules would place
"<tt class="samp">import site</tt>" somewhere near the top of their code.  This is no
longer necessary.

<P>
This will append site-specific paths to the module search path.
<a id='l2h-768'><!--x--></a>
<P>
It starts by constructing up to four directories from a head and a
tail part.  For the head part, it uses <code>sys.prefix</code> and
<code>sys.exec_prefix</code>; empty heads are skipped.  For
the tail part, it uses the empty string (on Macintosh or Windows) or
it uses first <span class="file">lib/python2.3/site-packages</span> and then
<span class="file">lib/site-python</span> (on <font style="font-variant: small-caps;">Unix</font>).  For each of the distinct
head-tail combinations, it sees if it refers to an existing directory,
and if so, adds it to <code>sys.path</code> and also inspects the newly added 
path for configuration files.
<a id='l2h-769'><!--x--></a><a id='l2h-770'><!--x--></a>
<P>
A path configuration file is a file whose name has the form
<span class="file"><var>package</var>.pth</span>; its contents are additional items (one
per line) to be added to <code>sys.path</code>.  Non-existing items are
never added to <code>sys.path</code>, but no check is made that the item
refers to a directory (rather than a file).  No item is added to
<code>sys.path</code> more than once.  Blank lines and lines beginning with
<code>#</code> are skipped.  Lines starting with <code>import</code> are executed.
<a id='l2h-772'><!--x--></a>
<a id='l2h-771'><!--x--></a>
<P>
For example, suppose <code>sys.prefix</code> and <code>sys.exec_prefix</code> are
set to <span class="file">/usr/local</span>.  The Python 2.3.4 library is then
installed in <span class="file">/usr/local/lib/python2.3</span> (where only the
first three characters of <code>sys.version</code> are used to form the
installation path name).  Suppose this has a subdirectory
<span class="file">/usr/local/lib/python2.3/site-packages</span> with three
subsubdirectories, <span class="file">foo</span>, <span class="file">bar</span> and <span class="file">spam</span>, and two
path configuration files, <span class="file">foo.pth</span> and <span class="file">bar.pth</span>.  Assume
<span class="file">foo.pth</span> contains the following:

<P>
<div class="verbatim"><pre>
# foo package configuration

foo
bar
bletch
</pre></div>

<P>
and <span class="file">bar.pth</span> contains:

<P>
<div class="verbatim"><pre>
# bar package configuration

bar
</pre></div>

<P>
Then the following directories are added to <code>sys.path</code>, in this
order:

<P>
<div class="verbatim"><pre>
/usr/local/lib/python2.3/site-packages/bar
/usr/local/lib/python2.3/site-packages/foo
</pre></div>

<P>
Note that <span class="file">bletch</span> is omitted because it doesn't exist; the
<span class="file">bar</span> directory precedes the <span class="file">foo</span> directory because
<span class="file">bar.pth</span> comes alphabetically before <span class="file">foo.pth</span>; and
<span class="file">spam</span> is omitted because it is not mentioned in either path
configuration file.

<P>
After these path manipulations, an attempt is made to import a module
named <tt class="module">sitecustomize</tt><a id='l2h-773'><!--x--></a>, which can
perform arbitrary site-specific customizations.  If this import fails
with an <tt class="exception">ImportError</tt> exception, it is silently ignored.

<P>
Note that for some non-<font style="font-variant: small-caps;">Unix</font> systems, <code>sys.prefix</code> and
<code>sys.exec_prefix</code> are empty, and the path manipulations are
skipped; however the import of
<tt class="module">sitecustomize</tt><a id='l2h-774'><!--x--></a> is still attempted.

<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.27 new  " 
  rel="prev" title="3.27 new  " 
  href="module-new.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. Python Runtime Services" 
  rel="parent" title="3. Python Runtime Services" 
  href="python.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.29 user  " 
  rel="next" title="3.29 user  " 
  href="module-user.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-new.html">3.27 new  </A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="python.html">3. Python Runtime Services</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-user.html">3.29 user  </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>