Sophie

Sophie

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

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>Importing Modules &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="Utilities" href="utilities.html" />
    <link rel="next" title="Data marshalling support" href="marshal.html" />
    <link rel="prev" title="Operating System Utilities" href="sys.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="marshal.html" title="Data marshalling support"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="sys.html" title="Operating System Utilities"
             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" >Python/C API Reference Manual</a> &raquo;</li>
          <li><a href="utilities.html" accesskey="U">Utilities</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="importing-modules">
<span id="importing"></span><h1>Importing Modules<a class="headerlink" href="#importing-modules" title="Permalink to this headline">¶</a></h1>
<dl class="function">
<dt id="PyImport_ImportModule">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyImport_ImportModule</tt><big>(</big>const char<em>&nbsp;*name</em><big>)</big><a class="headerlink" href="#PyImport_ImportModule" title="Permalink to this definition">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p id="index-0">This is a simplified interface to <a class="reference internal" href="#PyImport_ImportModuleEx" title="PyImport_ImportModuleEx"><tt class="xref c c-func docutils literal"><span class="pre">PyImport_ImportModuleEx()</span></tt></a> below,
leaving the <em>globals</em> and <em>locals</em> arguments set to <em>NULL</em> and <em>level</em> set
to 0.  When the <em>name</em>
argument contains a dot (when it specifies a submodule of a package), the
<em>fromlist</em> argument is set to the list <tt class="docutils literal"><span class="pre">['*']</span></tt> so that the return value is the
named module rather than the top-level package containing it as would otherwise
be the case.  (Unfortunately, this has an additional side effect when <em>name</em> in
fact specifies a subpackage instead of a submodule: the submodules specified in
the package&#8217;s <tt class="docutils literal"><span class="pre">__all__</span></tt> variable are  loaded.)  Return a new reference to the
imported module, or <em>NULL</em> with an exception set on failure.  A failing
import of a module doesn&#8217;t leave the module in <a class="reference internal" href="../library/sys.html#sys.modules" title="sys.modules"><tt class="xref py py-data docutils literal"><span class="pre">sys.modules</span></tt></a>.</p>
<p>This function always uses absolute imports.</p>
</dd></dl>

<dl class="function">
<dt id="PyImport_ImportModuleNoBlock">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyImport_ImportModuleNoBlock</tt><big>(</big>const char<em>&nbsp;*name</em><big>)</big><a class="headerlink" href="#PyImport_ImportModuleNoBlock" title="Permalink to this definition">¶</a></dt>
<dd><p>This version of <a class="reference internal" href="#PyImport_ImportModule" title="PyImport_ImportModule"><tt class="xref c c-func docutils literal"><span class="pre">PyImport_ImportModule()</span></tt></a> does not block. It&#8217;s intended
to be used in C functions that import other modules to execute a function.
The import may block if another thread holds the import lock. The function
<a class="reference internal" href="#PyImport_ImportModuleNoBlock" title="PyImport_ImportModuleNoBlock"><tt class="xref c c-func docutils literal"><span class="pre">PyImport_ImportModuleNoBlock()</span></tt></a> never blocks. It first tries to fetch
the module from sys.modules and falls back to <a class="reference internal" href="#PyImport_ImportModule" title="PyImport_ImportModule"><tt class="xref c c-func docutils literal"><span class="pre">PyImport_ImportModule()</span></tt></a>
unless the lock is held, in which case the function will raise an
<a class="reference internal" href="../library/exceptions.html#ImportError" title="ImportError"><tt class="xref py py-exc docutils literal"><span class="pre">ImportError</span></tt></a>.</p>
</dd></dl>

<dl class="function">
<dt id="PyImport_ImportModuleEx">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyImport_ImportModuleEx</tt><big>(</big>char<em>&nbsp;*name</em>, <a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*globals</em>, <a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*locals</em>, <a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*fromlist</em><big>)</big><a class="headerlink" href="#PyImport_ImportModuleEx" title="Permalink to this definition">¶</a></dt>
<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
function <a class="reference internal" href="../library/functions.html#__import__" title="__import__"><tt class="xref py py-func docutils literal"><span class="pre">__import__()</span></tt></a>, as the standard <a class="reference internal" href="../library/functions.html#__import__" title="__import__"><tt class="xref py py-func docutils literal"><span class="pre">__import__()</span></tt></a> function calls
this function directly.</p>
<p>The return value is a new reference to the imported module or top-level
package, or <em>NULL</em> with an exception set on failure.  Like for
<a class="reference internal" href="../library/functions.html#__import__" title="__import__"><tt class="xref py py-func docutils literal"><span class="pre">__import__()</span></tt></a>, the return value when a submodule of a package was
requested is normally the top-level package, unless a non-empty <em>fromlist</em>
was given.</p>
<p>Failing imports remove incomplete module objects, like with
<a class="reference internal" href="#PyImport_ImportModule" title="PyImport_ImportModule"><tt class="xref c c-func docutils literal"><span class="pre">PyImport_ImportModule()</span></tt></a>.</p>
</dd></dl>

<dl class="function">
<dt id="PyImport_ImportModuleLevel">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyImport_ImportModuleLevel</tt><big>(</big>char<em>&nbsp;*name</em>, <a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*globals</em>, <a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*locals</em>, <a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*fromlist</em>, int<em>&nbsp;level</em><big>)</big><a class="headerlink" href="#PyImport_ImportModuleLevel" title="Permalink to this definition">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Import a module.  This is best described by referring to the built-in Python
function <a class="reference internal" href="../library/functions.html#__import__" title="__import__"><tt class="xref py py-func docutils literal"><span class="pre">__import__()</span></tt></a>, as the standard <a class="reference internal" href="../library/functions.html#__import__" title="__import__"><tt class="xref py py-func docutils literal"><span class="pre">__import__()</span></tt></a> function calls
this function directly.</p>
<p>The return value is a new reference to the imported module or top-level package,
or <em>NULL</em> with an exception set on failure.  Like for <a class="reference internal" href="../library/functions.html#__import__" title="__import__"><tt class="xref py py-func docutils literal"><span class="pre">__import__()</span></tt></a>,
the return value when a submodule of a package was requested is normally the
top-level package, unless a non-empty <em>fromlist</em> was given.</p>
</dd></dl>

<dl class="function">
<dt id="PyImport_Import">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyImport_Import</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*name</em><big>)</big><a class="headerlink" href="#PyImport_Import" title="Permalink to this definition">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>This is a higher-level interface that calls the current &#8220;import hook
function&#8221; (with an explicit <em>level</em> of 0, meaning absolute import).  It
invokes the <a class="reference internal" href="../library/functions.html#__import__" title="__import__"><tt class="xref py py-func docutils literal"><span class="pre">__import__()</span></tt></a> function from the <tt class="docutils literal"><span class="pre">__builtins__</span></tt> of the
current globals.  This means that the import is done using whatever import
hooks are installed in the current environment.</p>
<p>This function always uses absolute imports.</p>
</dd></dl>

<dl class="function">
<dt id="PyImport_ReloadModule">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyImport_ReloadModule</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*m</em><big>)</big><a class="headerlink" href="#PyImport_ReloadModule" title="Permalink to this definition">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Reload a module.  Return a new reference to the reloaded module, or <em>NULL</em> with
an exception set on failure (the module still exists in this case).</p>
</dd></dl>

<dl class="function">
<dt id="PyImport_AddModule">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyImport_AddModule</tt><big>(</big>const char<em>&nbsp;*name</em><big>)</big><a class="headerlink" href="#PyImport_AddModule" title="Permalink to this definition">¶</a></dt>
<dd><em class="refcount">Return value: Borrowed reference.</em><p>Return the module object corresponding to a module name.  The <em>name</em> argument
may be of the form <tt class="docutils literal"><span class="pre">package.module</span></tt>. First check the modules dictionary if
there&#8217;s one there, and if not, create a new one and insert it in the modules
dictionary. Return <em>NULL</em> with an exception set on failure.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This function does not load or import the module; if the module wasn&#8217;t already
loaded, you will get an empty module object. Use <a class="reference internal" href="#PyImport_ImportModule" title="PyImport_ImportModule"><tt class="xref c c-func docutils literal"><span class="pre">PyImport_ImportModule()</span></tt></a>
or one of its variants to import a module.  Package structures implied by a
dotted name for <em>name</em> are not created if not already present.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="PyImport_ExecCodeModule">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyImport_ExecCodeModule</tt><big>(</big>char<em>&nbsp;*name</em>, <a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*co</em><big>)</big><a class="headerlink" href="#PyImport_ExecCodeModule" title="Permalink to this definition">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p id="index-2">Given a module name (possibly of the form <tt class="docutils literal"><span class="pre">package.module</span></tt>) and a code object
read from a Python bytecode file or obtained from the built-in function
<a class="reference internal" href="../library/functions.html#compile" title="compile"><tt class="xref py py-func docutils literal"><span class="pre">compile()</span></tt></a>, load the module.  Return a new reference to the module object,
or <em>NULL</em> with an exception set if an error occurred.  <em>name</em>
is removed from <a class="reference internal" href="../library/sys.html#sys.modules" title="sys.modules"><tt class="xref py py-attr docutils literal"><span class="pre">sys.modules</span></tt></a> in error cases, even if <em>name</em> was already
in <a class="reference internal" href="../library/sys.html#sys.modules" title="sys.modules"><tt class="xref py py-attr docutils literal"><span class="pre">sys.modules</span></tt></a> on entry to <a class="reference internal" href="#PyImport_ExecCodeModule" title="PyImport_ExecCodeModule"><tt class="xref c c-func docutils literal"><span class="pre">PyImport_ExecCodeModule()</span></tt></a>.  Leaving
incompletely initialized modules in <a class="reference internal" href="../library/sys.html#sys.modules" title="sys.modules"><tt class="xref py py-attr docutils literal"><span class="pre">sys.modules</span></tt></a> is dangerous, as imports of
such modules have no way to know that the module object is an unknown (and
probably damaged with respect to the module author&#8217;s intents) state.</p>
<p>The module&#8217;s <tt class="xref py py-attr docutils literal"><span class="pre">__file__</span></tt> attribute will be set to the code object&#8217;s
<tt class="xref c c-member docutils literal"><span class="pre">co_filename</span></tt>.</p>
<p>This function will reload the module if it was already imported.  See
<a class="reference internal" href="#PyImport_ReloadModule" title="PyImport_ReloadModule"><tt class="xref c c-func docutils literal"><span class="pre">PyImport_ReloadModule()</span></tt></a> for the intended way to reload a module.</p>
<p>If <em>name</em> points to a dotted name of the form <tt class="docutils literal"><span class="pre">package.module</span></tt>, any package
structures not already created will still not be created.</p>
<p>See also <a class="reference internal" href="#PyImport_ExecCodeModuleEx" title="PyImport_ExecCodeModuleEx"><tt class="xref c c-func docutils literal"><span class="pre">PyImport_ExecCodeModuleEx()</span></tt></a> and
<a class="reference internal" href="#PyImport_ExecCodeModuleWithPathnames" title="PyImport_ExecCodeModuleWithPathnames"><tt class="xref c c-func docutils literal"><span class="pre">PyImport_ExecCodeModuleWithPathnames()</span></tt></a>.</p>
</dd></dl>

<dl class="function">
<dt id="PyImport_ExecCodeModuleEx">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyImport_ExecCodeModuleEx</tt><big>(</big>char<em>&nbsp;*name</em>, <a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*co</em>, char<em>&nbsp;*pathname</em><big>)</big><a class="headerlink" href="#PyImport_ExecCodeModuleEx" title="Permalink to this definition">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Like <a class="reference internal" href="#PyImport_ExecCodeModule" title="PyImport_ExecCodeModule"><tt class="xref c c-func docutils literal"><span class="pre">PyImport_ExecCodeModule()</span></tt></a>, but the <tt class="xref py py-attr docutils literal"><span class="pre">__file__</span></tt> attribute of
the module object is set to <em>pathname</em> if it is non-<tt class="docutils literal"><span class="pre">NULL</span></tt>.</p>
<p>See also <a class="reference internal" href="#PyImport_ExecCodeModuleWithPathnames" title="PyImport_ExecCodeModuleWithPathnames"><tt class="xref c c-func docutils literal"><span class="pre">PyImport_ExecCodeModuleWithPathnames()</span></tt></a>.</p>
</dd></dl>

<dl class="function">
<dt id="PyImport_ExecCodeModuleWithPathnames">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyImport_ExecCodeModuleWithPathnames</tt><big>(</big>char<em>&nbsp;*name</em>, <a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*co</em>, char<em>&nbsp;*pathname</em>, char<em>&nbsp;*cpathname</em><big>)</big><a class="headerlink" href="#PyImport_ExecCodeModuleWithPathnames" title="Permalink to this definition">¶</a></dt>
<dd><p>Like <a class="reference internal" href="#PyImport_ExecCodeModuleEx" title="PyImport_ExecCodeModuleEx"><tt class="xref c c-func docutils literal"><span class="pre">PyImport_ExecCodeModuleEx()</span></tt></a>, but the <tt class="xref py py-attr docutils literal"><span class="pre">__cached__</span></tt>
attribute of the module object is set to <em>cpathname</em> if it is
non-<tt class="docutils literal"><span class="pre">NULL</span></tt>.  Of the three functions, this is the preferred one to use.</p>
<p class="versionadded">
<span class="versionmodified">New in version 3.2.</span></p>
</dd></dl>

<dl class="function">
<dt id="PyImport_GetMagicNumber">
long <tt class="descname">PyImport_GetMagicNumber</tt><big>(</big><big>)</big><a class="headerlink" href="#PyImport_GetMagicNumber" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the magic number for Python bytecode files (a.k.a. <tt class="file docutils literal"><span class="pre">.pyc</span></tt> and
<tt class="file docutils literal"><span class="pre">.pyo</span></tt> files).  The magic number should be present in the first four bytes
of the bytecode file, in little-endian byte order.</p>
</dd></dl>

<dl class="function">
<dt id="PyImport_GetMagicTag">
const char * <tt class="descname">PyImport_GetMagicTag</tt><big>(</big><big>)</big><a class="headerlink" href="#PyImport_GetMagicTag" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the magic tag string for <span class="target" id="index-3"></span><a class="pep reference external" href="http://www.python.org/dev/peps/pep-3147"><strong>PEP 3147</strong></a> format Python bytecode file
names.</p>
<p class="versionadded">
<span class="versionmodified">New in version 3.2.</span></p>
</dd></dl>

<dl class="function">
<dt id="PyImport_GetModuleDict">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyImport_GetModuleDict</tt><big>(</big><big>)</big><a class="headerlink" href="#PyImport_GetModuleDict" title="Permalink to this definition">¶</a></dt>
<dd><em class="refcount">Return value: Borrowed reference.</em><p>Return the dictionary used for the module administration (a.k.a.
<tt class="docutils literal"><span class="pre">sys.modules</span></tt>).  Note that this is a per-interpreter variable.</p>
</dd></dl>

<dl class="function">
<dt id="PyImport_GetImporter">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyImport_GetImporter</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*path</em><big>)</big><a class="headerlink" href="#PyImport_GetImporter" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an importer object for a <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><tt class="xref py py-data docutils literal"><span class="pre">sys.path</span></tt></a>/<tt class="xref py py-attr docutils literal"><span class="pre">pkg.__path__</span></tt> item
<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"><tt class="xref py py-data docutils literal"><span class="pre">sys.path_importer_cache</span></tt></a>
dict.  If it wasn&#8217;t yet cached, traverse <a class="reference internal" href="../library/sys.html#sys.path_hooks" title="sys.path_hooks"><tt class="xref py py-data docutils literal"><span class="pre">sys.path_hooks</span></tt></a> until a hook
is found that can handle the path item.  Return <tt class="xref docutils literal"><span class="pre">None</span></tt> if no hook could;
this tells our caller it should fall back to the built-in import mechanism.
Cache the result in <a class="reference internal" href="../library/sys.html#sys.path_importer_cache" title="sys.path_importer_cache"><tt class="xref py py-data docutils literal"><span class="pre">sys.path_importer_cache</span></tt></a>.  Return a new reference
to the importer object.</p>
</dd></dl>

<dl class="function">
<dt id="_PyImport_Init">
void <tt class="descname">_PyImport_Init</tt><big>(</big><big>)</big><a class="headerlink" href="#_PyImport_Init" title="Permalink to this definition">¶</a></dt>
<dd><p>Initialize the import mechanism.  For internal use only.</p>
</dd></dl>

<dl class="function">
<dt id="PyImport_Cleanup">
void <tt class="descname">PyImport_Cleanup</tt><big>(</big><big>)</big><a class="headerlink" href="#PyImport_Cleanup" title="Permalink to this definition">¶</a></dt>
<dd><p>Empty the module table.  For internal use only.</p>
</dd></dl>

<dl class="function">
<dt id="_PyImport_Fini">
void <tt class="descname">_PyImport_Fini</tt><big>(</big><big>)</big><a class="headerlink" href="#_PyImport_Fini" title="Permalink to this definition">¶</a></dt>
<dd><p>Finalize the import mechanism.  For internal use only.</p>
</dd></dl>

<dl class="function">
<dt id="_PyImport_FindExtension">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">_PyImport_FindExtension</tt><big>(</big>char<em>&nbsp;*</em>, char<em>&nbsp;*</em><big>)</big><a class="headerlink" href="#_PyImport_FindExtension" title="Permalink to this definition">¶</a></dt>
<dd><p>For internal use only.</p>
</dd></dl>

<dl class="function">
<dt id="_PyImport_FixupExtension">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">_PyImport_FixupExtension</tt><big>(</big>char<em>&nbsp;*</em>, char<em>&nbsp;*</em><big>)</big><a class="headerlink" href="#_PyImport_FixupExtension" title="Permalink to this definition">¶</a></dt>
<dd><p>For internal use only.</p>
</dd></dl>

<dl class="function">
<dt id="PyImport_ImportFrozenModule">
int <tt class="descname">PyImport_ImportFrozenModule</tt><big>(</big>char<em>&nbsp;*name</em><big>)</big><a class="headerlink" href="#PyImport_ImportFrozenModule" title="Permalink to this definition">¶</a></dt>
<dd><p>Load a frozen module named <em>name</em>.  Return <tt class="docutils literal"><span class="pre">1</span></tt> for success, <tt class="docutils literal"><span class="pre">0</span></tt> if the
module is not found, and <tt class="docutils literal"><span class="pre">-1</span></tt> with an exception set if the initialization
failed.  To access the imported module on a successful load, use
<a class="reference internal" href="#PyImport_ImportModule" title="PyImport_ImportModule"><tt class="xref c c-func docutils literal"><span class="pre">PyImport_ImportModule()</span></tt></a>.  (Note the misnomer &#8212; this function would
reload the module if it was already imported.)</p>
</dd></dl>

<dl class="type">
<dt id="_frozen">
struct <tt class="descname">_frozen</tt><a class="headerlink" href="#_frozen" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-4">This is the structure type definition for frozen module descriptors, as
generated by the <strong class="program">freeze</strong> utility (see <tt class="file docutils literal"><span class="pre">Tools/freeze/</span></tt> in the
Python source distribution).  Its definition, found in <tt class="file docutils literal"><span class="pre">Include/import.h</span></tt>,
is:</p>
<div class="highlight-c"><div class="highlight"><pre><span class="k">struct</span> <span class="n">_frozen</span> <span class="p">{</span>
    <span class="kt">char</span> <span class="o">*</span><span class="n">name</span><span class="p">;</span>
    <span class="kt">unsigned</span> <span class="kt">char</span> <span class="o">*</span><span class="n">code</span><span class="p">;</span>
    <span class="kt">int</span> <span class="n">size</span><span class="p">;</span>
<span class="p">};</span>
</pre></div>
</div>
</dd></dl>

<dl class="var">
<dt id="PyImport_FrozenModules">
struct <a class="reference internal" href="#_frozen" title="_frozen">_frozen</a>* <tt class="descname">PyImport_FrozenModules</tt><a class="headerlink" href="#PyImport_FrozenModules" title="Permalink to this definition">¶</a></dt>
<dd><p>This pointer is initialized to point to an array of <tt class="xref c c-type docutils literal"><span class="pre">struct</span> <span class="pre">_frozen</span></tt>
records, terminated by one whose members are all <em>NULL</em> or zero.  When a frozen
module is imported, it is searched in this table.  Third-party code could play
tricks with this to provide a dynamically created collection of frozen modules.</p>
</dd></dl>

<dl class="function">
<dt id="PyImport_AppendInittab">
int <tt class="descname">PyImport_AppendInittab</tt><big>(</big>const char<em>&nbsp;*name</em>, <a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>*<em>&nbsp;(*initfunc)(void)</em><big>)</big><a class="headerlink" href="#PyImport_AppendInittab" title="Permalink to this definition">¶</a></dt>
<dd><p>Add a single module to the existing table of built-in modules.  This is a
convenience wrapper around <a class="reference internal" href="#PyImport_ExtendInittab" title="PyImport_ExtendInittab"><tt class="xref c c-func docutils literal"><span class="pre">PyImport_ExtendInittab()</span></tt></a>, returning <tt class="docutils literal"><span class="pre">-1</span></tt> if
the table could not be extended.  The new module can be imported by the name
<em>name</em>, and uses the function <em>initfunc</em> as the initialization function called
on the first attempted import.  This should be called before
<a class="reference internal" href="init.html#Py_Initialize" title="Py_Initialize"><tt class="xref c c-func docutils literal"><span class="pre">Py_Initialize()</span></tt></a>.</p>
</dd></dl>

<dl class="type">
<dt id="_inittab">
struct <tt class="descname">_inittab</tt><a class="headerlink" href="#_inittab" title="Permalink to this definition">¶</a></dt>
<dd><p>Structure describing a single entry in the list of built-in modules.  Each of
these structures gives the name and initialization function for a module built
into the interpreter.  Programs which embed Python may use an array of these
structures in conjunction with <a class="reference internal" href="#PyImport_ExtendInittab" title="PyImport_ExtendInittab"><tt class="xref c c-func docutils literal"><span class="pre">PyImport_ExtendInittab()</span></tt></a> to provide
additional built-in modules.  The structure is defined in
<tt class="file docutils literal"><span class="pre">Include/import.h</span></tt> as:</p>
<div class="highlight-c"><div class="highlight"><pre><span class="k">struct</span> <span class="n">_inittab</span> <span class="p">{</span>
    <span class="kt">char</span> <span class="o">*</span><span class="n">name</span><span class="p">;</span>
    <span class="n">PyObject</span><span class="o">*</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>
<span class="p">};</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="PyImport_ExtendInittab">
int <tt class="descname">PyImport_ExtendInittab</tt><big>(</big>struct <a class="reference internal" href="#_inittab" title="_inittab">_inittab</a><em>&nbsp;*newtab</em><big>)</big><a class="headerlink" href="#PyImport_ExtendInittab" title="Permalink to this definition">¶</a></dt>
<dd><p>Add a collection of modules to the table of built-in modules.  The <em>newtab</em>
array must end with a sentinel entry which contains <em>NULL</em> for the <tt class="xref py py-attr docutils literal"><span class="pre">name</span></tt>
field; failure to provide the sentinel value can result in a memory fault.
Returns <tt class="docutils literal"><span class="pre">0</span></tt> on success or <tt class="docutils literal"><span class="pre">-1</span></tt> if insufficient memory could be allocated to
extend the internal table.  In the event of failure, no modules are added to the
internal table.  This should be called before <a class="reference internal" href="init.html#Py_Initialize" title="Py_Initialize"><tt class="xref c c-func docutils literal"><span class="pre">Py_Initialize()</span></tt></a>.</p>
</dd></dl>

</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h4>Previous topic</h4>
  <p class="topless"><a href="sys.html"
                        title="previous chapter">Operating System Utilities</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="marshal.html"
                        title="next chapter">Data marshalling support</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/c-api/import.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="marshal.html" title="Data marshalling support"
             >next</a> |</li>
        <li class="right" >
          <a href="sys.html" title="Operating System Utilities"
             >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" >Python/C API Reference Manual</a> &raquo;</li>
          <li><a href="utilities.html" >Utilities</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>