Sophie

Sophie

distrib > Mandriva > 2010.1 > x86_64 > media > contrib-backports > by-pkgid > 3ba3bd1608c672ba2129b098a48e9e4d > files > 771

python3-docs-3.2.2-3mdv2010.2.noarch.rpm



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>30.10. py_compile — Compile Python source files &mdash; Python v3.2.2 documentation</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '3.2.2',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python v3.2.2 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="top" title="Python v3.2.2 documentation" href="../index.html" />
    <link rel="up" title="30. Python Language Services" href="language.html" />
    <link rel="next" title="30.11. compileall — Byte-compile Python libraries" href="compileall.html" />
    <link rel="prev" title="30.9. pyclbr — Python class browser support" href="pyclbr.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
 

  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="compileall.html" title="30.11. compileall — Byte-compile Python libraries"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="pyclbr.html" title="30.9. pyclbr — Python class browser support"
             accesskey="P">previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="../index.html">Python v3.2.2 documentation</a> &raquo;</li>

          <li><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li><a href="language.html" accesskey="U">30. Python Language Services</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-py_compile">
<span id="py-compile-compile-python-source-files"></span><h1>30.10. <a class="reference internal" href="#module-py_compile" title="py_compile: Generate byte-code files from Python source files."><tt class="xref py py-mod docutils literal"><span class="pre">py_compile</span></tt></a> &#8212; Compile Python source files<a class="headerlink" href="#module-py_compile" title="Permalink to this headline">¶</a></h1>
<p id="index-0"><strong>Source code:</strong> <a class="reference external" href="http://hg.python.org/cpython/file/3.2/Lib/py_compile.py">Lib/py_compile.py</a></p>
<hr class="docutils" />
<p>The <a class="reference internal" href="#module-py_compile" title="py_compile: Generate byte-code files from Python source files."><tt class="xref py py-mod docutils literal"><span class="pre">py_compile</span></tt></a> module provides a function to generate a byte-code file
from a source file, and another function used when the module source file is
invoked as a script.</p>
<p>Though not often needed, this function can be useful when installing modules for
shared use, especially if some of the users may not have permission to write the
byte-code cache files in the directory containing the source code.</p>
<dl class="exception">
<dt id="py_compile.PyCompileError">
<em class="property">exception </em><tt class="descclassname">py_compile.</tt><tt class="descname">PyCompileError</tt><a class="headerlink" href="#py_compile.PyCompileError" title="Permalink to this definition">¶</a></dt>
<dd><p>Exception raised when an error occurs while attempting to compile the file.</p>
</dd></dl>

<dl class="function">
<dt id="py_compile.compile">
<tt class="descclassname">py_compile.</tt><tt class="descname">compile</tt><big>(</big><em>file</em>, <em>cfile=None</em>, <em>dfile=None</em>, <em>doraise=False</em>, <em>optimize=-1</em><big>)</big><a class="headerlink" href="#py_compile.compile" title="Permalink to this definition">¶</a></dt>
<dd><p>Compile a source file to byte-code and write out the byte-code cache  file.
The source code is loaded from the file name <em>file</em>.  The  byte-code is
written to <em>cfile</em>, which defaults to the <span class="target" id="index-1"></span><a class="pep reference external" href="http://www.python.org/dev/peps/pep-3147"><strong>PEP 3147</strong></a> path, ending in
<tt class="docutils literal"><span class="pre">.pyc</span></tt> (<tt class="docutils literal"><span class="pre">.pyo</span></tt> if optimization is enabled in the current interpreter).
For example, if <em>file</em> is <tt class="docutils literal"><span class="pre">/foo/bar/baz.py</span></tt> <em>cfile</em> will default to
<tt class="docutils literal"><span class="pre">/foo/bar/__pycache__/baz.cpython-32.pyc</span></tt> for Python 3.2.  If <em>dfile</em> is
specified, it is used as the name of the source file in error messages when
instead of <em>file</em>.  If <em>doraise</em> is true, a <a class="reference internal" href="#py_compile.PyCompileError" title="py_compile.PyCompileError"><tt class="xref py py-exc docutils literal"><span class="pre">PyCompileError</span></tt></a> is raised
when an error is encountered while compiling <em>file</em>. If <em>doraise</em> is false
(the default), an error string is written to <tt class="docutils literal"><span class="pre">sys.stderr</span></tt>, but no exception
is raised.  This function returns the path to byte-compiled file, i.e.
whatever <em>cfile</em> value was used.</p>
<p><em>optimize</em> controls the optimization level and is passed to the built-in
<a class="reference internal" href="functions.html#compile" title="compile"><tt class="xref py py-func docutils literal"><span class="pre">compile()</span></tt></a> function.  The default of <tt class="docutils literal"><span class="pre">-1</span></tt> selects the optimization
level of the current interpreter.</p>
<p class="versionchanged">
<span class="versionmodified">Changed in version 3.2: </span>Changed default value of <em>cfile</em> to be <span class="target" id="index-2"></span><a class="pep reference external" href="http://www.python.org/dev/peps/pep-3147"><strong>PEP 3147</strong></a>-compliant.  Previous
default was <em>file</em> + <tt class="docutils literal"><span class="pre">'c'</span></tt> (<tt class="docutils literal"><span class="pre">'o'</span></tt> if optimization was enabled).
Also added the <em>optimize</em> parameter.</p>
</dd></dl>

<dl class="function">
<dt id="py_compile.main">
<tt class="descclassname">py_compile.</tt><tt class="descname">main</tt><big>(</big><em>args=None</em><big>)</big><a class="headerlink" href="#py_compile.main" title="Permalink to this definition">¶</a></dt>
<dd><p>Compile several source files.  The files named in <em>args</em> (or on the command
line, if <em>args</em> is <tt class="xref docutils literal"><span class="pre">None</span></tt>) are compiled and the resulting bytecode is
cached in the normal manner.  This function does not search a directory
structure to locate source files; it only compiles files named explicitly.
If <tt class="docutils literal"><span class="pre">'-'</span></tt> is the only parameter in args, the list of files is taken from
standard input.</p>
<p class="versionchanged">
<span class="versionmodified">Changed in version 3.2: </span>Added support for <tt class="docutils literal"><span class="pre">'-'</span></tt>.</p>
</dd></dl>

<p>When this module is run as a script, the <a class="reference internal" href="#py_compile.main" title="py_compile.main"><tt class="xref py py-func docutils literal"><span class="pre">main()</span></tt></a> is used to compile all the
files named on the command line.  The exit status is nonzero if one of the files
could not be compiled.</p>
<div class="admonition-see-also admonition seealso">
<p class="first admonition-title">See also</p>
<dl class="last docutils">
<dt>Module <a class="reference internal" href="compileall.html#module-compileall" title="compileall: Tools for byte-compiling all Python source files in a directory tree."><tt class="xref py py-mod docutils literal"><span class="pre">compileall</span></tt></a></dt>
<dd>Utilities to compile all Python source files in a directory tree.</dd>
</dl>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h4>Previous topic</h4>
  <p class="topless"><a href="pyclbr.html"
                        title="previous chapter">30.9. <tt class="docutils literal"><span class="pre">pyclbr</span></tt> &#8212; Python class browser support</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="compileall.html"
                        title="next chapter">30.11. <tt class="docutils literal docutils literal docutils literal"><span class="pre">compileall</span></tt> &#8212; Byte-compile Python libraries</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
  <li><a href="../bugs.html">Report a Bug</a></li>
  <li><a href="../_sources/library/py_compile.txt"
         rel="nofollow">Show Source</a></li>
</ul>

<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" size="18" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="compileall.html" title="30.11. compileall — Byte-compile Python libraries"
             >next</a> |</li>
        <li class="right" >
          <a href="pyclbr.html" title="30.9. pyclbr — Python class browser support"
             >previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="../index.html">Python v3.2.2 documentation</a> &raquo;</li>

          <li><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li><a href="language.html" >30. Python Language Services</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
    &copy; <a href="../copyright.html">Copyright</a> 1990-2011, Python Software Foundation.
    <br />
    The Python Software Foundation is a non-profit corporation.  
    <a href="http://www.python.org/psf/donations/">Please donate.</a>
    <br />
    Last updated on Sep 04, 2011.
    <a href="../bugs.html">Found a bug</a>?
    <br />
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7.
    </div>

  </body>
</html>