~dkuhlman/python-training-materials/Materials

« back to all changes in this revision

Viewing changes to python-2.7.12-docs-html/library/py_compile.html

  • Committer: Dave Kuhlman
  • Date: 2017-04-15 16:24:56 UTC
  • Revision ID: dkuhlman@davekuhlman.org-20170415162456-iav9vozzg4iwqwv3
Updated docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 
2
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
3
 
 
4
 
 
5
<html xmlns="http://www.w3.org/1999/xhtml">
 
6
  <head>
 
7
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 
8
    
 
9
    <title>32.10. py_compile — Compile Python source files &mdash; Python 2.7.12 documentation</title>
 
10
    
 
11
    <link rel="stylesheet" href="../_static/classic.css" type="text/css" />
 
12
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
 
13
    
 
14
    <script type="text/javascript">
 
15
      var DOCUMENTATION_OPTIONS = {
 
16
        URL_ROOT:    '../',
 
17
        VERSION:     '2.7.12',
 
18
        COLLAPSE_INDEX: false,
 
19
        FILE_SUFFIX: '.html',
 
20
        HAS_SOURCE:  true
 
21
      };
 
22
    </script>
 
23
    <script type="text/javascript" src="../_static/jquery.js"></script>
 
24
    <script type="text/javascript" src="../_static/underscore.js"></script>
 
25
    <script type="text/javascript" src="../_static/doctools.js"></script>
 
26
    <script type="text/javascript" src="../_static/sidebar.js"></script>
 
27
    <link rel="search" type="application/opensearchdescription+xml"
 
28
          title="Search within Python 2.7.12 documentation"
 
29
          href="../_static/opensearch.xml"/>
 
30
    <link rel="author" title="About these documents" href="../about.html" />
 
31
    <link rel="copyright" title="Copyright" href="../copyright.html" />
 
32
    <link rel="top" title="Python 2.7.12 documentation" href="../contents.html" />
 
33
    <link rel="up" title="32. Python Language Services" href="language.html" />
 
34
    <link rel="next" title="32.11. compileall — Byte-compile Python libraries" href="compileall.html" />
 
35
    <link rel="prev" title="32.9. pyclbr — Python class browser support" href="pyclbr.html" />
 
36
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
 
37
    <script type="text/javascript" src="../_static/copybutton.js"></script>
 
38
    <script type="text/javascript" src="../_static/version_switch.js"></script>
 
39
 
 
40
    
 
41
 
 
42
  </head>
 
43
  <body role="document">  
 
44
    <div class="related" role="navigation" aria-label="related navigation">
 
45
      <h3>Navigation</h3>
 
46
      <ul>
 
47
        <li class="right" style="margin-right: 10px">
 
48
          <a href="../genindex.html" title="General Index"
 
49
             accesskey="I">index</a></li>
 
50
        <li class="right" >
 
51
          <a href="../py-modindex.html" title="Python Module Index"
 
52
             >modules</a> |</li>
 
53
        <li class="right" >
 
54
          <a href="compileall.html" title="32.11. compileall — Byte-compile Python libraries"
 
55
             accesskey="N">next</a> |</li>
 
56
        <li class="right" >
 
57
          <a href="pyclbr.html" title="32.9. pyclbr — Python class browser support"
 
58
             accesskey="P">previous</a> |</li>
 
59
        <li><img src="../_static/py.png" alt=""
 
60
                 style="vertical-align: middle; margin-top: -1px"/></li>
 
61
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
 
62
        <li>
 
63
          <span class="version_switcher_placeholder">2.7.12</span>
 
64
          <a href="../index.html">Documentation</a> &raquo;
 
65
        </li>
 
66
 
 
67
          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &raquo;</li>
 
68
          <li class="nav-item nav-item-2"><a href="language.html" accesskey="U">32. Python Language Services</a> &raquo;</li> 
 
69
      </ul>
 
70
    </div>    
 
71
 
 
72
    <div class="document">
 
73
      <div class="documentwrapper">
 
74
        <div class="bodywrapper">
 
75
          <div class="body" role="main">
 
76
            
 
77
  <div class="section" id="module-py_compile">
 
78
<span id="py-compile-compile-python-source-files"></span><h1>32.10. <a class="reference internal" href="#module-py_compile" title="py_compile: Generate byte-code files from Python source files."><code class="xref py py-mod docutils literal"><span class="pre">py_compile</span></code></a> &#8212; Compile Python source files<a class="headerlink" href="#module-py_compile" title="Permalink to this headline">¶</a></h1>
 
79
<p id="index-0"><strong>Source code:</strong> <a class="reference external" href="https://hg.python.org/cpython/file/2.7/Lib/py_compile.py">Lib/py_compile.py</a></p>
 
80
<hr class="docutils" />
 
81
<p>The <a class="reference internal" href="#module-py_compile" title="py_compile: Generate byte-code files from Python source files."><code class="xref py py-mod docutils literal"><span class="pre">py_compile</span></code></a> module provides a function to generate a byte-code file
 
82
from a source file, and another function used when the module source file is
 
83
invoked as a script.</p>
 
84
<p>Though not often needed, this function can be useful when installing modules for
 
85
shared use, especially if some of the users may not have permission to write the
 
86
byte-code cache files in the directory containing the source code.</p>
 
87
<dl class="exception">
 
88
<dt id="py_compile.PyCompileError">
 
89
<em class="property">exception </em><code class="descclassname">py_compile.</code><code class="descname">PyCompileError</code><a class="headerlink" href="#py_compile.PyCompileError" title="Permalink to this definition">¶</a></dt>
 
90
<dd><p>Exception raised when an error occurs while attempting to compile the file.</p>
 
91
</dd></dl>
 
92
 
 
93
<dl class="function">
 
94
<dt id="py_compile.compile">
 
95
<code class="descclassname">py_compile.</code><code class="descname">compile</code><span class="sig-paren">(</span><em>file</em><span class="optional">[</span>, <em>cfile</em><span class="optional">[</span>, <em>dfile</em><span class="optional">[</span>, <em>doraise</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#py_compile.compile" title="Permalink to this definition">¶</a></dt>
 
96
<dd><p>Compile a source file to byte-code and write out the byte-code cache  file.  The
 
97
source code is loaded from the file named <em>file</em>.  The  byte-code is written to
 
98
<em>cfile</em>, which defaults to <em>file</em> <code class="docutils literal"><span class="pre">+</span></code> <code class="docutils literal"><span class="pre">'c'</span></code> (<code class="docutils literal"><span class="pre">'o'</span></code> if optimization is
 
99
enabled in the current interpreter).  If <em>dfile</em> is specified, it is used as the
 
100
name of the source file in error messages instead of <em>file</em>.  If <em>doraise</em> is
 
101
true, a <a class="reference internal" href="#py_compile.PyCompileError" title="py_compile.PyCompileError"><code class="xref py py-exc docutils literal"><span class="pre">PyCompileError</span></code></a> is raised when an error is encountered while
 
102
compiling <em>file</em>. If <em>doraise</em> is false (the default), an error string is
 
103
written to <code class="docutils literal"><span class="pre">sys.stderr</span></code>, but no exception is raised.</p>
 
104
</dd></dl>
 
105
 
 
106
<dl class="function">
 
107
<dt id="py_compile.main">
 
108
<code class="descclassname">py_compile.</code><code class="descname">main</code><span class="sig-paren">(</span><span class="optional">[</span><em>args</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#py_compile.main" title="Permalink to this definition">¶</a></dt>
 
109
<dd><p>Compile several source files.  The files named in <em>args</em> (or on the command
 
110
line, if <em>args</em> is not specified) are compiled and the resulting bytecode is
 
111
cached in the normal manner.  This function does not search a directory
 
112
structure to locate source files; it only compiles files named explicitly.
 
113
If <code class="docutils literal"><span class="pre">'-'</span></code> is the only parameter in args, the list of files is taken from
 
114
standard input.</p>
 
115
<div class="versionchanged">
 
116
<p><span class="versionmodified">Changed in version 2.7: </span>Added support for <code class="docutils literal"><span class="pre">'-'</span></code>.</p>
 
117
</div>
 
118
</dd></dl>
 
119
 
 
120
<p>When this module is run as a script, the <a class="reference internal" href="#py_compile.main" title="py_compile.main"><code class="xref py py-func docutils literal"><span class="pre">main()</span></code></a> is used to compile all the
 
121
files named on the command line.  The exit status is nonzero if one of the files
 
122
could not be compiled.</p>
 
123
<div class="versionchanged">
 
124
<p><span class="versionmodified">Changed in version 2.6: </span>Added the nonzero exit status when module is run as a script.</p>
 
125
</div>
 
126
<div class="admonition seealso">
 
127
<p class="first admonition-title">See also</p>
 
128
<dl class="last docutils">
 
129
<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."><code class="xref py py-mod docutils literal"><span class="pre">compileall</span></code></a></dt>
 
130
<dd>Utilities to compile all Python source files in a directory tree.</dd>
 
131
</dl>
 
132
</div>
 
133
</div>
 
134
 
 
135
 
 
136
          </div>
 
137
        </div>
 
138
      </div>
 
139
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
 
140
        <div class="sphinxsidebarwrapper">
 
141
  <h4>Previous topic</h4>
 
142
  <p class="topless"><a href="pyclbr.html"
 
143
                        title="previous chapter">32.9. <code class="docutils literal"><span class="pre">pyclbr</span></code> &#8212; Python class browser support</a></p>
 
144
  <h4>Next topic</h4>
 
145
  <p class="topless"><a href="compileall.html"
 
146
                        title="next chapter">32.11. <code class="docutils literal"><span class="pre">compileall</span></code> &#8212; Byte-compile Python libraries</a></p>
 
147
<h3>This Page</h3>
 
148
<ul class="this-page-menu">
 
149
  <li><a href="../bugs.html">Report a Bug</a></li>
 
150
  <li><a href="../_sources/library/py_compile.txt"
 
151
         rel="nofollow">Show Source</a></li>
 
152
</ul>
 
153
 
 
154
<div id="searchbox" style="display: none" role="search">
 
155
  <h3>Quick search</h3>
 
156
    <form class="search" action="../search.html" method="get">
 
157
      <input type="text" name="q" />
 
158
      <input type="submit" value="Go" />
 
159
      <input type="hidden" name="check_keywords" value="yes" />
 
160
      <input type="hidden" name="area" value="default" />
 
161
    </form>
 
162
    <p class="searchtip" style="font-size: 90%">
 
163
    Enter search terms or a module, class or function name.
 
164
    </p>
 
165
</div>
 
166
<script type="text/javascript">$('#searchbox').show(0);</script>
 
167
        </div>
 
168
      </div>
 
169
      <div class="clearer"></div>
 
170
    </div>  
 
171
    <div class="related" role="navigation" aria-label="related navigation">
 
172
      <h3>Navigation</h3>
 
173
      <ul>
 
174
        <li class="right" style="margin-right: 10px">
 
175
          <a href="../genindex.html" title="General Index"
 
176
             >index</a></li>
 
177
        <li class="right" >
 
178
          <a href="../py-modindex.html" title="Python Module Index"
 
179
             >modules</a> |</li>
 
180
        <li class="right" >
 
181
          <a href="compileall.html" title="32.11. compileall — Byte-compile Python libraries"
 
182
             >next</a> |</li>
 
183
        <li class="right" >
 
184
          <a href="pyclbr.html" title="32.9. pyclbr — Python class browser support"
 
185
             >previous</a> |</li>
 
186
        <li><img src="../_static/py.png" alt=""
 
187
                 style="vertical-align: middle; margin-top: -1px"/></li>
 
188
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
 
189
        <li>
 
190
          <span class="version_switcher_placeholder">2.7.12</span>
 
191
          <a href="../index.html">Documentation</a> &raquo;
 
192
        </li>
 
193
 
 
194
          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &raquo;</li>
 
195
          <li class="nav-item nav-item-2"><a href="language.html" >32. Python Language Services</a> &raquo;</li> 
 
196
      </ul>
 
197
    </div>  
 
198
    <div class="footer">
 
199
    &copy; <a href="../copyright.html">Copyright</a> 1990-2016, Python Software Foundation.
 
200
    <br />
 
201
    The Python Software Foundation is a non-profit corporation.
 
202
    <a href="https://www.python.org/psf/donations/">Please donate.</a>
 
203
    <br />
 
204
    Last updated on Sep 20, 2016.
 
205
    <a href="../bugs.html">Found a bug</a>?
 
206
    <br />
 
207
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.3.3.
 
208
    </div>
 
209
 
 
210
  </body>
 
211
</html>
 
 
b'\\ No newline at end of file'