~dkuhlman/python-training-materials/Materials

« back to all changes in this revision

Viewing changes to python-2.7.11-docs-html/c-api/import.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>Importing Modules &mdash; Python 2.7.11 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.11',
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.11 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.11 documentation" href="../contents.html" />
33
 
    <link rel="up" title="Utilities" href="utilities.html" />
34
 
    <link rel="next" title="Data marshalling support" href="marshal.html" />
35
 
    <link rel="prev" title="Operating System Utilities" href="sys.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="marshal.html" title="Data marshalling support"
55
 
             accesskey="N">next</a> |</li>
56
 
        <li class="right" >
57
 
          <a href="sys.html" title="Operating System Utilities"
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.11</span>
64
 
          <a href="../index.html">Documentation</a> &raquo;
65
 
        </li>
66
 
 
67
 
          <li class="nav-item nav-item-1"><a href="index.html" >Python/C API Reference Manual</a> &raquo;</li>
68
 
          <li class="nav-item nav-item-2"><a href="utilities.html" accesskey="U">Utilities</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="importing-modules">
78
 
<span id="importing"></span><h1>Importing Modules<a class="headerlink" href="#importing-modules" title="Permalink to this headline">¶</a></h1>
79
 
<dl class="function">
80
 
<dt id="c.PyImport_ImportModule">
81
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyImport_ImportModule</code><span class="sig-paren">(</span>const char<em>&nbsp;*name</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyImport_ImportModule" title="Permalink to this definition">¶</a></dt>
82
 
<dd><em class="refcount">Return value: New reference.</em><p id="index-0">This is a simplified interface to <a class="reference internal" href="#c.PyImport_ImportModuleEx" title="PyImport_ImportModuleEx"><code class="xref c c-func docutils literal"><span class="pre">PyImport_ImportModuleEx()</span></code></a> below,
83
 
leaving the <em>globals</em> and <em>locals</em> arguments set to <em>NULL</em> and <em>level</em> set
84
 
to 0.  When the <em>name</em>
85
 
argument contains a dot (when it specifies a submodule of a package), the
86
 
<em>fromlist</em> argument is set to the list <code class="docutils literal"><span class="pre">['*']</span></code> so that the return value is the
87
 
named module rather than the top-level package containing it as would otherwise
88
 
be the case.  (Unfortunately, this has an additional side effect when <em>name</em> in
89
 
fact specifies a subpackage instead of a submodule: the submodules specified in
90
 
the package&#8217;s <code class="docutils literal"><span class="pre">__all__</span></code> variable are  loaded.)  Return a new reference to the
91
 
imported module, or <em>NULL</em> with an exception set on failure.  Before Python 2.4,
92
 
the module may still be created in the failure case &#8212; examine <code class="docutils literal"><span class="pre">sys.modules</span></code>
93
 
to find out.  Starting with Python 2.4, a failing import of a module no longer
94
 
leaves the module in <code class="docutils literal"><span class="pre">sys.modules</span></code>.</p>
95
 
<div class="versionchanged">
96
 
<p><span class="versionmodified">Changed in version 2.4: </span>Failing imports remove incomplete module objects.</p>
97
 
</div>
98
 
<div class="versionchanged">
99
 
<p><span class="versionmodified">Changed in version 2.6: </span>Always uses absolute imports.</p>
100
 
</div>
101
 
</dd></dl>
102
 
 
103
 
<dl class="function">
104
 
<dt id="c.PyImport_ImportModuleNoBlock">
105
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyImport_ImportModuleNoBlock</code><span class="sig-paren">(</span>const char<em>&nbsp;*name</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyImport_ImportModuleNoBlock" title="Permalink to this definition">¶</a></dt>
106
 
<dd><p>This version of <a class="reference internal" href="#c.PyImport_ImportModule" title="PyImport_ImportModule"><code class="xref c c-func docutils literal"><span class="pre">PyImport_ImportModule()</span></code></a> does not block. It&#8217;s intended
107
 
to be used in C functions that import other modules to execute a function.
108
 
The import may block if another thread holds the import lock. The function
109
 
<a class="reference internal" href="#c.PyImport_ImportModuleNoBlock" title="PyImport_ImportModuleNoBlock"><code class="xref c c-func docutils literal"><span class="pre">PyImport_ImportModuleNoBlock()</span></code></a> never blocks. It first tries to fetch
110
 
the module from sys.modules and falls back to <a class="reference internal" href="#c.PyImport_ImportModule" title="PyImport_ImportModule"><code class="xref c c-func docutils literal"><span class="pre">PyImport_ImportModule()</span></code></a>
111
 
unless the lock is held, in which case the function will raise an
112
 
<a class="reference internal" href="../library/exceptions.html#exceptions.ImportError" title="exceptions.ImportError"><code class="xref py py-exc docutils literal"><span class="pre">ImportError</span></code></a>.</p>
113
 
<div class="versionadded">
114
 
<p><span class="versionmodified">New in version 2.6.</span></p>
115
 
</div>
116
 
</dd></dl>
117
 
 
118
 
<dl class="function">
119
 
<dt id="c.PyImport_ImportModuleEx">
120
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyImport_ImportModuleEx</code><span class="sig-paren">(</span>char<em>&nbsp;*name</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*globals</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*locals</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*fromlist</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyImport_ImportModuleEx" title="Permalink to this definition">¶</a></dt>
121
 
<dd><em class="refcount">Return value: New reference.</em><p id="index-1">Import a module.  This is best described by referring to the built-in Python
122
 
function <a class="reference internal" href="../library/functions.html#__import__" title="__import__"><code class="xref py py-func docutils literal"><span class="pre">__import__()</span></code></a>, as the standard <a class="reference internal" href="../library/functions.html#__import__" title="__import__"><code class="xref py py-func docutils literal"><span class="pre">__import__()</span></code></a> function calls
123
 
this function directly.</p>
124
 
<p>The return value is a new reference to the imported module or top-level package,
125
 
or <em>NULL</em> with an exception set on failure (before Python 2.4, the module may
126
 
still be created in this case).  Like for <a class="reference internal" href="../library/functions.html#__import__" title="__import__"><code class="xref py py-func docutils literal"><span class="pre">__import__()</span></code></a>, the return value
127
 
when a submodule of a package was requested is normally the top-level package,
128
 
unless a non-empty <em>fromlist</em> was given.</p>
129
 
<div class="versionchanged">
130
 
<p><span class="versionmodified">Changed in version 2.4: </span>Failing imports remove incomplete module objects.</p>
131
 
</div>
132
 
<div class="versionchanged">
133
 
<p><span class="versionmodified">Changed in version 2.6: </span>The function is an alias for <a class="reference internal" href="#c.PyImport_ImportModuleLevel" title="PyImport_ImportModuleLevel"><code class="xref c c-func docutils literal"><span class="pre">PyImport_ImportModuleLevel()</span></code></a> with
134
 
-1 as level, meaning relative import.</p>
135
 
</div>
136
 
</dd></dl>
137
 
 
138
 
<dl class="function">
139
 
<dt id="c.PyImport_ImportModuleLevel">
140
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyImport_ImportModuleLevel</code><span class="sig-paren">(</span>char<em>&nbsp;*name</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*globals</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*locals</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*fromlist</em>, int<em>&nbsp;level</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyImport_ImportModuleLevel" title="Permalink to this definition">¶</a></dt>
141
 
<dd><em class="refcount">Return value: New reference.</em><p>Import a module.  This is best described by referring to the built-in Python
142
 
function <a class="reference internal" href="../library/functions.html#__import__" title="__import__"><code class="xref py py-func docutils literal"><span class="pre">__import__()</span></code></a>, as the standard <a class="reference internal" href="../library/functions.html#__import__" title="__import__"><code class="xref py py-func docutils literal"><span class="pre">__import__()</span></code></a> function calls
143
 
this function directly.</p>
144
 
<p>The return value is a new reference to the imported module or top-level package,
145
 
or <em>NULL</em> with an exception set on failure.  Like for <a class="reference internal" href="../library/functions.html#__import__" title="__import__"><code class="xref py py-func docutils literal"><span class="pre">__import__()</span></code></a>,
146
 
the return value when a submodule of a package was requested is normally the
147
 
top-level package, unless a non-empty <em>fromlist</em> was given.</p>
148
 
<div class="versionadded">
149
 
<p><span class="versionmodified">New in version 2.5.</span></p>
150
 
</div>
151
 
</dd></dl>
152
 
 
153
 
<dl class="function">
154
 
<dt id="c.PyImport_Import">
155
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyImport_Import</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*name</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyImport_Import" title="Permalink to this definition">¶</a></dt>
156
 
<dd><em class="refcount">Return value: New reference.</em><p id="index-2">This is a higher-level interface that calls the current &#8220;import hook function&#8221;.
157
 
It invokes the <a class="reference internal" href="../library/functions.html#__import__" title="__import__"><code class="xref py py-func docutils literal"><span class="pre">__import__()</span></code></a> function from the <code class="docutils literal"><span class="pre">__builtins__</span></code> of the
158
 
current globals.  This means that the import is done using whatever import hooks
159
 
are installed in the current environment, e.g. by <a class="reference internal" href="../library/rexec.html#module-rexec" title="rexec: Basic restricted execution framework. (deprecated)"><code class="xref py py-mod docutils literal"><span class="pre">rexec</span></code></a> or <code class="xref py py-mod docutils literal"><span class="pre">ihooks</span></code>.</p>
160
 
<div class="versionchanged">
161
 
<p><span class="versionmodified">Changed in version 2.6: </span>Always uses absolute imports.</p>
162
 
</div>
163
 
</dd></dl>
164
 
 
165
 
<dl class="function">
166
 
<dt id="c.PyImport_ReloadModule">
167
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyImport_ReloadModule</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*m</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyImport_ReloadModule" title="Permalink to this definition">¶</a></dt>
168
 
<dd><em class="refcount">Return value: New reference.</em><p id="index-3">Reload a module.  This is best described by referring to the built-in Python
169
 
function <a class="reference internal" href="../library/functions.html#reload" title="reload"><code class="xref py py-func docutils literal"><span class="pre">reload()</span></code></a>, as the standard <a class="reference internal" href="../library/functions.html#reload" title="reload"><code class="xref py py-func docutils literal"><span class="pre">reload()</span></code></a> function calls this
170
 
function directly.  Return a new reference to the reloaded module, or <em>NULL</em>
171
 
with an exception set on failure (the module still exists in this case).</p>
172
 
</dd></dl>
173
 
 
174
 
<dl class="function">
175
 
<dt id="c.PyImport_AddModule">
176
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyImport_AddModule</code><span class="sig-paren">(</span>const char<em>&nbsp;*name</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyImport_AddModule" title="Permalink to this definition">¶</a></dt>
177
 
<dd><em class="refcount">Return value: Borrowed reference.</em><p>Return the module object corresponding to a module name.  The <em>name</em> argument
178
 
may be of the form <code class="docutils literal"><span class="pre">package.module</span></code>. First check the modules dictionary if
179
 
there&#8217;s one there, and if not, create a new one and insert it in the modules
180
 
dictionary. Return <em>NULL</em> with an exception set on failure.</p>
181
 
<div class="admonition note">
182
 
<p class="first admonition-title">Note</p>
183
 
<p class="last">This function does not load or import the module; if the module wasn&#8217;t already
184
 
loaded, you will get an empty module object. Use <a class="reference internal" href="#c.PyImport_ImportModule" title="PyImport_ImportModule"><code class="xref c c-func docutils literal"><span class="pre">PyImport_ImportModule()</span></code></a>
185
 
or one of its variants to import a module.  Package structures implied by a
186
 
dotted name for <em>name</em> are not created if not already present.</p>
187
 
</div>
188
 
</dd></dl>
189
 
 
190
 
<dl class="function">
191
 
<dt id="c.PyImport_ExecCodeModule">
192
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyImport_ExecCodeModule</code><span class="sig-paren">(</span>char<em>&nbsp;*name</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*co</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyImport_ExecCodeModule" title="Permalink to this definition">¶</a></dt>
193
 
<dd><em class="refcount">Return value: New reference.</em><p id="index-4">Given a module name (possibly of the form <code class="docutils literal"><span class="pre">package.module</span></code>) and a code object
194
 
read from a Python bytecode file or obtained from the built-in function
195
 
<a class="reference internal" href="../library/functions.html#compile" title="compile"><code class="xref py py-func docutils literal"><span class="pre">compile()</span></code></a>, load the module.  Return a new reference to the module object,
196
 
or <em>NULL</em> with an exception set if an error occurred.  Before Python 2.4, the
197
 
module could still be created in error cases.  Starting with Python 2.4, <em>name</em>
198
 
is removed from <a class="reference internal" href="../library/sys.html#sys.modules" title="sys.modules"><code class="xref py py-attr docutils literal"><span class="pre">sys.modules</span></code></a> in error cases, and even if <em>name</em> was already
199
 
in <a class="reference internal" href="../library/sys.html#sys.modules" title="sys.modules"><code class="xref py py-attr docutils literal"><span class="pre">sys.modules</span></code></a> on entry to <a class="reference internal" href="#c.PyImport_ExecCodeModule" title="PyImport_ExecCodeModule"><code class="xref c c-func docutils literal"><span class="pre">PyImport_ExecCodeModule()</span></code></a>.  Leaving
200
 
incompletely initialized modules in <a class="reference internal" href="../library/sys.html#sys.modules" title="sys.modules"><code class="xref py py-attr docutils literal"><span class="pre">sys.modules</span></code></a> is dangerous, as imports of
201
 
such modules have no way to know that the module object is an unknown (and
202
 
probably damaged with respect to the module author&#8217;s intents) state.</p>
203
 
<p>The module&#8217;s <code class="xref py py-attr docutils literal"><span class="pre">__file__</span></code> attribute will be set to the code object&#8217;s
204
 
<code class="xref c c-member docutils literal"><span class="pre">co_filename</span></code>.</p>
205
 
<p>This function will reload the module if it was already imported.  See
206
 
<a class="reference internal" href="#c.PyImport_ReloadModule" title="PyImport_ReloadModule"><code class="xref c c-func docutils literal"><span class="pre">PyImport_ReloadModule()</span></code></a> for the intended way to reload a module.</p>
207
 
<p>If <em>name</em> points to a dotted name of the form <code class="docutils literal"><span class="pre">package.module</span></code>, any package
208
 
structures not already created will still not be created.</p>
209
 
<div class="versionchanged">
210
 
<p><span class="versionmodified">Changed in version 2.4: </span><em>name</em> is removed from <a class="reference internal" href="../library/sys.html#sys.modules" title="sys.modules"><code class="xref py py-attr docutils literal"><span class="pre">sys.modules</span></code></a> in error cases.</p>
211
 
</div>
212
 
</dd></dl>
213
 
 
214
 
<dl class="function">
215
 
<dt id="c.PyImport_ExecCodeModuleEx">
216
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyImport_ExecCodeModuleEx</code><span class="sig-paren">(</span>char<em>&nbsp;*name</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*co</em>, char<em>&nbsp;*pathname</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyImport_ExecCodeModuleEx" title="Permalink to this definition">¶</a></dt>
217
 
<dd><em class="refcount">Return value: New reference.</em><p>Like <a class="reference internal" href="#c.PyImport_ExecCodeModule" title="PyImport_ExecCodeModule"><code class="xref c c-func docutils literal"><span class="pre">PyImport_ExecCodeModule()</span></code></a>, but the <code class="xref py py-attr docutils literal"><span class="pre">__file__</span></code> attribute of
218
 
the module object is set to <em>pathname</em> if it is non-<code class="docutils literal"><span class="pre">NULL</span></code>.</p>
219
 
</dd></dl>
220
 
 
221
 
<dl class="function">
222
 
<dt id="c.PyImport_GetMagicNumber">
223
 
long <code class="descname">PyImport_GetMagicNumber</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyImport_GetMagicNumber" title="Permalink to this definition">¶</a></dt>
224
 
<dd><p>Return the magic number for Python bytecode files (a.k.a. <code class="file docutils literal"><span class="pre">.pyc</span></code> and
225
 
<code class="file docutils literal"><span class="pre">.pyo</span></code> files).  The magic number should be present in the first four bytes
226
 
of the bytecode file, in little-endian byte order.</p>
227
 
</dd></dl>
228
 
 
229
 
<dl class="function">
230
 
<dt id="c.PyImport_GetModuleDict">
231
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyImport_GetModuleDict</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyImport_GetModuleDict" title="Permalink to this definition">¶</a></dt>
232
 
<dd><em class="refcount">Return value: Borrowed reference.</em><p>Return the dictionary used for the module administration (a.k.a.
233
 
<code class="docutils literal"><span class="pre">sys.modules</span></code>).  Note that this is a per-interpreter variable.</p>
234
 
</dd></dl>
235
 
 
236
 
<dl class="function">
237
 
<dt id="c.PyImport_GetImporter">
238
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyImport_GetImporter</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*path</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyImport_GetImporter" title="Permalink to this definition">¶</a></dt>
239
 
<dd><p>Return an importer object for a <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal"><span class="pre">sys.path</span></code></a>/<code class="xref py py-attr docutils literal"><span class="pre">pkg.__path__</span></code> item
240
 
<em>path</em>, possibly by fetching it from the <a class="reference internal" href="../library/sys.html#sys.path_importer_cache" title="sys.path_importer_cache"><code class="xref py py-data docutils literal"><span class="pre">sys.path_importer_cache</span></code></a>
241
 
dict.  If it wasn&#8217;t yet cached, traverse <a class="reference internal" href="../library/sys.html#sys.path_hooks" title="sys.path_hooks"><code class="xref py py-data docutils literal"><span class="pre">sys.path_hooks</span></code></a> until a hook
242
 
is found that can handle the path item.  Return <code class="docutils literal"><span class="pre">None</span></code> if no hook could;
243
 
this tells our caller it should fall back to the built-in import mechanism.
244
 
Cache the result in <a class="reference internal" href="../library/sys.html#sys.path_importer_cache" title="sys.path_importer_cache"><code class="xref py py-data docutils literal"><span class="pre">sys.path_importer_cache</span></code></a>.  Return a new reference
245
 
to the importer object.</p>
246
 
<div class="versionadded">
247
 
<p><span class="versionmodified">New in version 2.6.</span></p>
248
 
</div>
249
 
</dd></dl>
250
 
 
251
 
<dl class="function">
252
 
<dt id="c._PyImport_Init">
253
 
void <code class="descname">_PyImport_Init</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#c._PyImport_Init" title="Permalink to this definition">¶</a></dt>
254
 
<dd><p>Initialize the import mechanism.  For internal use only.</p>
255
 
</dd></dl>
256
 
 
257
 
<dl class="function">
258
 
<dt id="c.PyImport_Cleanup">
259
 
void <code class="descname">PyImport_Cleanup</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyImport_Cleanup" title="Permalink to this definition">¶</a></dt>
260
 
<dd><p>Empty the module table.  For internal use only.</p>
261
 
</dd></dl>
262
 
 
263
 
<dl class="function">
264
 
<dt id="c._PyImport_Fini">
265
 
void <code class="descname">_PyImport_Fini</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#c._PyImport_Fini" title="Permalink to this definition">¶</a></dt>
266
 
<dd><p>Finalize the import mechanism.  For internal use only.</p>
267
 
</dd></dl>
268
 
 
269
 
<dl class="function">
270
 
<dt id="c._PyImport_FindExtension">
271
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">_PyImport_FindExtension</code><span class="sig-paren">(</span>char<em>&nbsp;*</em>, char<em>&nbsp;*</em><span class="sig-paren">)</span><a class="headerlink" href="#c._PyImport_FindExtension" title="Permalink to this definition">¶</a></dt>
272
 
<dd><p>For internal use only.</p>
273
 
</dd></dl>
274
 
 
275
 
<dl class="function">
276
 
<dt id="c._PyImport_FixupExtension">
277
 
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">_PyImport_FixupExtension</code><span class="sig-paren">(</span>char<em>&nbsp;*</em>, char<em>&nbsp;*</em><span class="sig-paren">)</span><a class="headerlink" href="#c._PyImport_FixupExtension" title="Permalink to this definition">¶</a></dt>
278
 
<dd><p>For internal use only.</p>
279
 
</dd></dl>
280
 
 
281
 
<dl class="function">
282
 
<dt id="c.PyImport_ImportFrozenModule">
283
 
int <code class="descname">PyImport_ImportFrozenModule</code><span class="sig-paren">(</span>char<em>&nbsp;*name</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyImport_ImportFrozenModule" title="Permalink to this definition">¶</a></dt>
284
 
<dd><p>Load a frozen module named <em>name</em>.  Return <code class="docutils literal"><span class="pre">1</span></code> for success, <code class="docutils literal"><span class="pre">0</span></code> if the
285
 
module is not found, and <code class="docutils literal"><span class="pre">-1</span></code> with an exception set if the initialization
286
 
failed.  To access the imported module on a successful load, use
287
 
<a class="reference internal" href="#c.PyImport_ImportModule" title="PyImport_ImportModule"><code class="xref c c-func docutils literal"><span class="pre">PyImport_ImportModule()</span></code></a>.  (Note the misnomer &#8212; this function would
288
 
reload the module if it was already imported.)</p>
289
 
</dd></dl>
290
 
 
291
 
<dl class="type">
292
 
<dt id="c._frozen">
293
 
struct <code class="descname">_frozen</code><a class="headerlink" href="#c._frozen" title="Permalink to this definition">¶</a></dt>
294
 
<dd><p id="index-5">This is the structure type definition for frozen module descriptors, as
295
 
generated by the <strong class="program">freeze</strong> utility (see <code class="file docutils literal"><span class="pre">Tools/freeze/</span></code> in the
296
 
Python source distribution).  Its definition, found in <code class="file docutils literal"><span class="pre">Include/import.h</span></code>,
297
 
is:</p>
298
 
<div class="highlight-c"><div class="highlight"><pre><span class="k">struct</span> <span class="n">_frozen</span> <span class="p">{</span>
299
 
    <span class="kt">char</span> <span class="o">*</span><span class="n">name</span><span class="p">;</span>
300
 
    <span class="kt">unsigned</span> <span class="kt">char</span> <span class="o">*</span><span class="n">code</span><span class="p">;</span>
301
 
    <span class="kt">int</span> <span class="n">size</span><span class="p">;</span>
302
 
<span class="p">};</span>
303
 
</pre></div>
304
 
</div>
305
 
</dd></dl>
306
 
 
307
 
<dl class="var">
308
 
<dt id="c.PyImport_FrozenModules">
309
 
struct <a class="reference internal" href="#c._frozen" title="_frozen">_frozen</a>* <code class="descname">PyImport_FrozenModules</code><a class="headerlink" href="#c.PyImport_FrozenModules" title="Permalink to this definition">¶</a></dt>
310
 
<dd><p>This pointer is initialized to point to an array of <code class="xref c c-type docutils literal"><span class="pre">struct</span> <span class="pre">_frozen</span></code>
311
 
records, terminated by one whose members are all <em>NULL</em> or zero.  When a frozen
312
 
module is imported, it is searched in this table.  Third-party code could play
313
 
tricks with this to provide a dynamically created collection of frozen modules.</p>
314
 
</dd></dl>
315
 
 
316
 
<dl class="function">
317
 
<dt id="c.PyImport_AppendInittab">
318
 
int <code class="descname">PyImport_AppendInittab</code><span class="sig-paren">(</span>const char<em>&nbsp;*name</em>, void (<em>*initfunc</em>)(void)<span class="sig-paren">)</span><a class="headerlink" href="#c.PyImport_AppendInittab" title="Permalink to this definition">¶</a></dt>
319
 
<dd><p>Add a single module to the existing table of built-in modules.  This is a
320
 
convenience wrapper around <a class="reference internal" href="#c.PyImport_ExtendInittab" title="PyImport_ExtendInittab"><code class="xref c c-func docutils literal"><span class="pre">PyImport_ExtendInittab()</span></code></a>, returning <code class="docutils literal"><span class="pre">-1</span></code> if
321
 
the table could not be extended.  The new module can be imported by the name
322
 
<em>name</em>, and uses the function <em>initfunc</em> as the initialization function called
323
 
on the first attempted import.  This should be called before
324
 
<a class="reference internal" href="init.html#c.Py_Initialize" title="Py_Initialize"><code class="xref c c-func docutils literal"><span class="pre">Py_Initialize()</span></code></a>.</p>
325
 
</dd></dl>
326
 
 
327
 
<dl class="type">
328
 
<dt id="c._inittab">
329
 
struct <code class="descname">_inittab</code><a class="headerlink" href="#c._inittab" title="Permalink to this definition">¶</a></dt>
330
 
<dd><p>Structure describing a single entry in the list of built-in modules.  Each of
331
 
these structures gives the name and initialization function for a module built
332
 
into the interpreter.  Programs which embed Python may use an array of these
333
 
structures in conjunction with <a class="reference internal" href="#c.PyImport_ExtendInittab" title="PyImport_ExtendInittab"><code class="xref c c-func docutils literal"><span class="pre">PyImport_ExtendInittab()</span></code></a> to provide
334
 
additional built-in modules.  The structure is defined in
335
 
<code class="file docutils literal"><span class="pre">Include/import.h</span></code> as:</p>
336
 
<div class="highlight-c"><div class="highlight"><pre><span class="k">struct</span> <span class="n">_inittab</span> <span class="p">{</span>
337
 
    <span class="kt">char</span> <span class="o">*</span><span class="n">name</span><span class="p">;</span>
338
 
    <span class="kt">void</span> <span class="p">(</span><span class="o">*</span><span class="n">initfunc</span><span class="p">)(</span><span class="kt">void</span><span class="p">);</span>
339
 
<span class="p">};</span>
340
 
</pre></div>
341
 
</div>
342
 
</dd></dl>
343
 
 
344
 
<dl class="function">
345
 
<dt id="c.PyImport_ExtendInittab">
346
 
int <code class="descname">PyImport_ExtendInittab</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c._inittab" title="_inittab">_inittab</a><em>&nbsp;*newtab</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyImport_ExtendInittab" title="Permalink to this definition">¶</a></dt>
347
 
<dd><p>Add a collection of modules to the table of built-in modules.  The <em>newtab</em>
348
 
array must end with a sentinel entry which contains <em>NULL</em> for the <code class="xref py py-attr docutils literal"><span class="pre">name</span></code>
349
 
field; failure to provide the sentinel value can result in a memory fault.
350
 
Returns <code class="docutils literal"><span class="pre">0</span></code> on success or <code class="docutils literal"><span class="pre">-1</span></code> if insufficient memory could be allocated to
351
 
extend the internal table.  In the event of failure, no modules are added to the
352
 
internal table.  This should be called before <a class="reference internal" href="init.html#c.Py_Initialize" title="Py_Initialize"><code class="xref c c-func docutils literal"><span class="pre">Py_Initialize()</span></code></a>.</p>
353
 
</dd></dl>
354
 
 
355
 
</div>
356
 
 
357
 
 
358
 
          </div>
359
 
        </div>
360
 
      </div>
361
 
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
362
 
        <div class="sphinxsidebarwrapper">
363
 
  <h4>Previous topic</h4>
364
 
  <p class="topless"><a href="sys.html"
365
 
                        title="previous chapter">Operating System Utilities</a></p>
366
 
  <h4>Next topic</h4>
367
 
  <p class="topless"><a href="marshal.html"
368
 
                        title="next chapter">Data marshalling support</a></p>
369
 
<h3>This Page</h3>
370
 
<ul class="this-page-menu">
371
 
  <li><a href="../bugs.html">Report a Bug</a></li>
372
 
  <li><a href="../_sources/c-api/import.txt"
373
 
         rel="nofollow">Show Source</a></li>
374
 
</ul>
375
 
 
376
 
<div id="searchbox" style="display: none" role="search">
377
 
  <h3>Quick search</h3>
378
 
    <form class="search" action="../search.html" method="get">
379
 
      <input type="text" name="q" />
380
 
      <input type="submit" value="Go" />
381
 
      <input type="hidden" name="check_keywords" value="yes" />
382
 
      <input type="hidden" name="area" value="default" />
383
 
    </form>
384
 
    <p class="searchtip" style="font-size: 90%">
385
 
    Enter search terms or a module, class or function name.
386
 
    </p>
387
 
</div>
388
 
<script type="text/javascript">$('#searchbox').show(0);</script>
389
 
        </div>
390
 
      </div>
391
 
      <div class="clearer"></div>
392
 
    </div>  
393
 
    <div class="related" role="navigation" aria-label="related navigation">
394
 
      <h3>Navigation</h3>
395
 
      <ul>
396
 
        <li class="right" style="margin-right: 10px">
397
 
          <a href="../genindex.html" title="General Index"
398
 
             >index</a></li>
399
 
        <li class="right" >
400
 
          <a href="../py-modindex.html" title="Python Module Index"
401
 
             >modules</a> |</li>
402
 
        <li class="right" >
403
 
          <a href="marshal.html" title="Data marshalling support"
404
 
             >next</a> |</li>
405
 
        <li class="right" >
406
 
          <a href="sys.html" title="Operating System Utilities"
407
 
             >previous</a> |</li>
408
 
        <li><img src="../_static/py.png" alt=""
409
 
                 style="vertical-align: middle; margin-top: -1px"/></li>
410
 
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
411
 
        <li>
412
 
          <span class="version_switcher_placeholder">2.7.11</span>
413
 
          <a href="../index.html">Documentation</a> &raquo;
414
 
        </li>
415
 
 
416
 
          <li class="nav-item nav-item-1"><a href="index.html" >Python/C API Reference Manual</a> &raquo;</li>
417
 
          <li class="nav-item nav-item-2"><a href="utilities.html" >Utilities</a> &raquo;</li> 
418
 
      </ul>
419
 
    </div>  
420
 
    <div class="footer">
421
 
    &copy; <a href="../copyright.html">Copyright</a> 1990-2016, Python Software Foundation.
422
 
    <br />
423
 
    The Python Software Foundation is a non-profit corporation.
424
 
    <a href="https://www.python.org/psf/donations/">Please donate.</a>
425
 
    <br />
426
 
    Last updated on Jan 23, 2016.
427
 
    <a href="../bugs.html">Found a bug</a>?
428
 
    <br />
429
 
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.3.3.
430
 
    </div>
431
 
 
432
 
  </body>
433
 
</html>
 
 
b'\\ No newline at end of file'