Linux cpanel.rrshost.in 5.15.0-25-generic #25-Ubuntu SMP Wed Mar 30 15:54:22 UTC 2022 x86_64
Apache
: 109.123.238.221 | : 172.69.17.14
128 Domain
8.2.28
aev999
Terminal
AUTO ROOT
Adminer
Backdoor Destroyer
Linux Exploit
Lock Shell
Lock File
Create User
CREATE RDP
PHP Mailer
BACKCONNECT
HASH IDENTIFIER
README
+ Create Folder
+ Create File
/
usr /
share /
doc /
python2.7 /
html /
c-api /
[ HOME SHELL ]
Name
Size
Permission
Action
abstract.html
7.8
KB
-rw-r--r--
allocation.html
24.04
KB
-rw-r--r--
arg.html
64.25
KB
-rw-r--r--
bool.html
11.44
KB
-rw-r--r--
buffer.html
58.49
KB
-rw-r--r--
bytearray.html
18.39
KB
-rw-r--r--
capsule.html
26.78
KB
-rw-r--r--
cell.html
13.74
KB
-rw-r--r--
class.html
14.3
KB
-rw-r--r--
cobject.html
15.67
KB
-rw-r--r--
code.html
15.57
KB
-rw-r--r--
codec.html
29.28
KB
-rw-r--r--
complex.html
25.03
KB
-rw-r--r--
concrete.html
15.93
KB
-rw-r--r--
conversion.html
29.24
KB
-rw-r--r--
datetime.html
35.92
KB
-rw-r--r--
descriptor.html
15.74
KB
-rw-r--r--
dict.html
42.03
KB
-rw-r--r--
exceptions.html
112.66
KB
-rw-r--r--
file.html
28.8
KB
-rw-r--r--
float.html
21.5
KB
-rw-r--r--
function.html
17.69
KB
-rw-r--r--
gcsupport.html
29.5
KB
-rw-r--r--
gen.html
9.84
KB
-rw-r--r--
import.html
43.14
KB
-rw-r--r--
index.html
13.69
KB
-rw-r--r--
init.html
122.91
KB
-rw-r--r--
int.html
24.28
KB
-rw-r--r--
intro.html
57.73
KB
-rw-r--r--
iter.html
11.38
KB
-rw-r--r--
iterator.html
13.32
KB
-rw-r--r--
list.html
31.45
KB
-rw-r--r--
long.html
39.54
KB
-rw-r--r--
mapping.html
20.85
KB
-rw-r--r--
marshal.html
18.82
KB
-rw-r--r--
memory.html
37.51
KB
-rw-r--r--
method.html
16.77
KB
-rw-r--r--
module.html
21.95
KB
-rw-r--r--
none.html
8.76
KB
-rw-r--r--
number.html
64.95
KB
-rw-r--r--
objbuffer.html
14.62
KB
-rw-r--r--
object.html
74.9
KB
-rw-r--r--
objimpl.html
7.59
KB
-rw-r--r--
refcounting.html
14.46
KB
-rw-r--r--
reflection.html
12.81
KB
-rw-r--r--
sequence.html
41.73
KB
-rw-r--r--
set.html
35.44
KB
-rw-r--r--
slice.html
16.89
KB
-rw-r--r--
string.html
46.73
KB
-rw-r--r--
structures.html
41.96
KB
-rw-r--r--
sys.html
26.72
KB
-rw-r--r--
tuple.html
27.17
KB
-rw-r--r--
type.html
19.18
KB
-rw-r--r--
typeobj.html
209.91
KB
-rw-r--r--
unicode.html
160.87
KB
-rw-r--r--
utilities.html
7.88
KB
-rw-r--r--
veryhigh.html
66.91
KB
-rw-r--r--
weakref.html
15.68
KB
-rw-r--r--
Delete
Unzip
Zip
${this.title}
Close
Code Editor : import.html
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" /> <title>Importing Modules — Python 2.7.18 documentation</title> <link rel="stylesheet" type="text/css" href="../_static/pygments.css" /> <link rel="stylesheet" type="text/css" href="../_static/classic.css" /> <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script> <script src="../_static/jquery.js"></script> <script src="../_static/underscore.js"></script> <script src="../_static/doctools.js"></script> <script src="../_static/sidebar.js"></script> <link rel="search" type="application/opensearchdescription+xml" title="Search within Python 2.7.18 documentation" href="../_static/opensearch.xml"/> <link rel="author" title="About these documents" href="../about.html" /> <link rel="index" title="Index" href="../genindex.html" /> <link rel="search" title="Search" href="../search.html" /> <link rel="copyright" title="Copyright" href="../copyright.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" /> <link rel="canonical" href="file:///usr/share/doc/python2.7/html/c-api/import.html" /> <script type="text/javascript" src="../_static/copybutton.js"></script> </head><body> <div id="outdated-warning" style="padding: .5em; text-align: center; background-color: #FFBABA; color: #6A0E0E;"> This document is for an old version of Python that is <a href="https://devguide.python.org/devcycle/#end-of-life-branches">no longer supported</a>. You should install the python3 and python3-doc packages and read the <a href="file:///usr/share/doc/python3-doc/html/c-api/import.html"> Python documentation for the Python3 version packaged in this release</a>. </div> <div class="related" role="navigation" aria-label="related navigation"> <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="https://www.python.org/">Python</a> »</li> <li> <a href="../index.html">Python 2.7.18 documentation</a> » </li> <li class="nav-item nav-item-1"><a href="index.html" >Python/C API Reference Manual</a> »</li> <li class="nav-item nav-item-2"><a href="utilities.html" accesskey="U">Utilities</a> »</li> <li class="nav-item nav-item-this"><a href="">Importing Modules</a></li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" role="main"> <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="c function"> <dt class="sig sig-object c" id="c.PyImport_ImportModule"> <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyImport_ImportModule</span></span></span><span class="sig-paren">(</span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">name</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyImport_ImportModule" title="Permalink to this definition">¶</a><br /></dt> <dd><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 notranslate"><span class="pre">PyImport_ImportModuleEx()</span></code></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 <code class="docutils literal notranslate"><span class="pre">['*']</span></code> 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’s <code class="docutils literal notranslate"><span class="pre">__all__</span></code> variable are loaded.) Return a new reference to the imported module, or <em>NULL</em> with an exception set on failure. Before Python 2.4, the module may still be created in the failure case — examine <code class="docutils literal notranslate"><span class="pre">sys.modules</span></code> to find out. Starting with Python 2.4, a failing import of a module no longer leaves the module in <code class="docutils literal notranslate"><span class="pre">sys.modules</span></code>.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.4: </span>Failing imports remove incomplete module objects.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.6: </span>Always uses absolute imports.</p> </div> </dd></dl> <dl class="c function"> <dt class="sig sig-object c" id="c.PyImport_ImportModuleNoBlock"> <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyImport_ImportModuleNoBlock</span></span></span><span class="sig-paren">(</span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">name</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyImport_ImportModuleNoBlock" title="Permalink to this definition">¶</a><br /></dt> <dd><p>This version of <a class="reference internal" href="#c.PyImport_ImportModule" title="PyImport_ImportModule"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyImport_ImportModule()</span></code></a> does not block. It’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="#c.PyImport_ImportModuleNoBlock" title="PyImport_ImportModuleNoBlock"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyImport_ImportModuleNoBlock()</span></code></a> never blocks. It first tries to fetch 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 notranslate"><span class="pre">PyImport_ImportModule()</span></code></a> unless the lock is held, in which case the function will raise an <code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 2.6.</span></p> </div> </dd></dl> <dl class="c function"> <dt class="sig sig-object c" id="c.PyImport_ImportModuleEx"> <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyImport_ImportModuleEx</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">name</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">globals</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">locals</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">fromlist</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyImport_ImportModuleEx" title="Permalink to this definition">¶</a><br /></dt> <dd><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__"><code class="xref py py-func docutils literal notranslate"><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 notranslate"><span class="pre">__import__()</span></code></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 (before Python 2.4, the module may 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 notranslate"><span class="pre">__import__()</span></code></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> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.4: </span>Failing imports remove incomplete module objects.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">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 notranslate"><span class="pre">PyImport_ImportModuleLevel()</span></code></a> with <code class="docutils literal notranslate"><span class="pre">-1</span></code> as level, meaning relative import.</p> </div> </dd></dl> <dl class="c function"> <dt class="sig sig-object c" id="c.PyImport_ImportModuleLevel"> <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyImport_ImportModuleLevel</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">name</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">globals</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">locals</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">fromlist</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">level</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyImport_ImportModuleLevel" title="Permalink to this definition">¶</a><br /></dt> <dd><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__"><code class="xref py py-func docutils literal notranslate"><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 notranslate"><span class="pre">__import__()</span></code></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__"><code class="xref py py-func docutils literal notranslate"><span class="pre">__import__()</span></code></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> <div class="versionadded"> <p><span class="versionmodified added">New in version 2.5.</span></p> </div> </dd></dl> <dl class="c function"> <dt class="sig sig-object c" id="c.PyImport_Import"> <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyImport_Import</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">name</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyImport_Import" title="Permalink to this definition">¶</a><br /></dt> <dd><p id="index-2">This is a higher-level interface that calls the current “import hook function”. It invokes the <a class="reference internal" href="../library/functions.html#import__" title="__import__"><code class="xref py py-func docutils literal notranslate"><span class="pre">__import__()</span></code></a> function from the <code class="docutils literal notranslate"><span class="pre">__builtins__</span></code> of the current globals. This means that the import is done using whatever import hooks 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 notranslate"><span class="pre">rexec</span></code></a> or <code class="xref py py-mod docutils literal notranslate"><span class="pre">ihooks</span></code>.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.6: </span>Always uses absolute imports.</p> </div> </dd></dl> <dl class="c function"> <dt class="sig sig-object c" id="c.PyImport_ReloadModule"> <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyImport_ReloadModule</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">m</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyImport_ReloadModule" title="Permalink to this definition">¶</a><br /></dt> <dd><p id="index-3">Reload a module. This is best described by referring to the built-in Python function <a class="reference internal" href="../library/functions.html#reload" title="reload"><code class="xref py py-func docutils literal notranslate"><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 notranslate"><span class="pre">reload()</span></code></a> function calls this function directly. 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="c function"> <dt class="sig sig-object c" id="c.PyImport_AddModule"> <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyImport_AddModule</span></span></span><span class="sig-paren">(</span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">name</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyImport_AddModule" title="Permalink to this definition">¶</a><br /></dt> <dd><p>Return the module object corresponding to a module name. The <em>name</em> argument may be of the form <code class="docutils literal notranslate"><span class="pre">package.module</span></code>. First check the modules dictionary if there’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="admonition-title">Note</p> <p>This function does not load or import the module; if the module wasn’t already 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 notranslate"><span class="pre">PyImport_ImportModule()</span></code></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="c function"> <dt class="sig sig-object c" id="c.PyImport_ExecCodeModule"> <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyImport_ExecCodeModule</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">name</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">co</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyImport_ExecCodeModule" title="Permalink to this definition">¶</a><br /></dt> <dd><p id="index-4">Given a module name (possibly of the form <code class="docutils literal notranslate"><span class="pre">package.module</span></code>) 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"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile()</span></code></a>, load the module. Return a new reference to the module object, or <em>NULL</em> with an exception set if an error occurred. Before Python 2.4, the module could still be created in error cases. Starting with Python 2.4, <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 notranslate"><span class="pre">sys.modules</span></code></a> in error cases, and even if <em>name</em> was already in <a class="reference internal" href="../library/sys.html#sys.modules" title="sys.modules"><code class="xref py py-attr docutils literal notranslate"><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 notranslate"><span class="pre">PyImport_ExecCodeModule()</span></code></a>. Leaving 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 notranslate"><span class="pre">sys.modules</span></code></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’s intents) state.</p> <p>The module’s <code class="xref py py-attr docutils literal notranslate"><span class="pre">__file__</span></code> attribute will be set to the code object’s <code class="xref c c-member docutils literal notranslate"><span class="pre">co_filename</span></code>.</p> <p>This function will reload the module if it was already imported. See <a class="reference internal" href="#c.PyImport_ReloadModule" title="PyImport_ReloadModule"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyImport_ReloadModule()</span></code></a> for the intended way to reload a module.</p> <p>If <em>name</em> points to a dotted name of the form <code class="docutils literal notranslate"><span class="pre">package.module</span></code>, any package structures not already created will still not be created.</p> <div class="versionchanged"> <p><span class="versionmodified changed">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 notranslate"><span class="pre">sys.modules</span></code></a> in error cases.</p> </div> </dd></dl> <dl class="c function"> <dt class="sig sig-object c" id="c.PyImport_ExecCodeModuleEx"> <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyImport_ExecCodeModuleEx</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">name</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">co</span></span>, <span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">pathname</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyImport_ExecCodeModuleEx" title="Permalink to this definition">¶</a><br /></dt> <dd><p>Like <a class="reference internal" href="#c.PyImport_ExecCodeModule" title="PyImport_ExecCodeModule"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyImport_ExecCodeModule()</span></code></a>, but the <code class="xref py py-attr docutils literal notranslate"><span class="pre">__file__</span></code> attribute of the module object is set to <em>pathname</em> if it is non-<code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p> </dd></dl> <dl class="c function"> <dt class="sig sig-object c" id="c.PyImport_GetMagicNumber"> <span class="kt"><span class="pre">long</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyImport_GetMagicNumber</span></span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyImport_GetMagicNumber" title="Permalink to this definition">¶</a><br /></dt> <dd><p>Return the magic number for Python bytecode files (a.k.a. <code class="file docutils literal notranslate"><span class="pre">.pyc</span></code> and <code class="file docutils literal notranslate"><span class="pre">.pyo</span></code> 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="c function"> <dt class="sig sig-object c" id="c.PyImport_GetModuleDict"> <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyImport_GetModuleDict</span></span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyImport_GetModuleDict" title="Permalink to this definition">¶</a><br /></dt> <dd><p>Return the dictionary used for the module administration (a.k.a. <code class="docutils literal notranslate"><span class="pre">sys.modules</span></code>). Note that this is a per-interpreter variable.</p> </dd></dl> <dl class="c function"> <dt class="sig sig-object c" id="c.PyImport_GetImporter"> <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyImport_GetImporter</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">path</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyImport_GetImporter" title="Permalink to this definition">¶</a><br /></dt> <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 notranslate"><span class="pre">sys.path</span></code></a>/<code class="xref py py-attr docutils literal notranslate"><span class="pre">pkg.__path__</span></code> 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"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path_importer_cache</span></code></a> dict. If it wasn’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 notranslate"><span class="pre">sys.path_hooks</span></code></a> until a hook is found that can handle the path item. Return <code class="docutils literal notranslate"><span class="pre">None</span></code> 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"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path_importer_cache</span></code></a>. Return a new reference to the importer object.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 2.6.</span></p> </div> </dd></dl> <dl class="c function"> <dt class="sig sig-object c" id="c._PyImport_Init"> <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">_PyImport_Init</span></span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#c._PyImport_Init" title="Permalink to this definition">¶</a><br /></dt> <dd><p>Initialize the import mechanism. For internal use only.</p> </dd></dl> <dl class="c function"> <dt class="sig sig-object c" id="c.PyImport_Cleanup"> <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyImport_Cleanup</span></span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyImport_Cleanup" title="Permalink to this definition">¶</a><br /></dt> <dd><p>Empty the module table. For internal use only.</p> </dd></dl> <dl class="c function"> <dt class="sig sig-object c" id="c._PyImport_Fini"> <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">_PyImport_Fini</span></span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#c._PyImport_Fini" title="Permalink to this definition">¶</a><br /></dt> <dd><p>Finalize the import mechanism. For internal use only.</p> </dd></dl> <dl class="c function"> <dt class="sig sig-object c" id="c._PyImport_FindExtension"> <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">_PyImport_FindExtension</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">char</span></span><span class="p"><span class="pre">*</span></span>, <span class="kt"><span class="pre">char</span></span><span class="p"><span class="pre">*</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c._PyImport_FindExtension" title="Permalink to this definition">¶</a><br /></dt> <dd><p>For internal use only.</p> </dd></dl> <dl class="c function"> <dt class="sig sig-object c" id="c._PyImport_FixupExtension"> <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">_PyImport_FixupExtension</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">char</span></span><span class="p"><span class="pre">*</span></span>, <span class="kt"><span class="pre">char</span></span><span class="p"><span class="pre">*</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c._PyImport_FixupExtension" title="Permalink to this definition">¶</a><br /></dt> <dd><p>For internal use only.</p> </dd></dl> <dl class="c function"> <dt class="sig sig-object c" id="c.PyImport_ImportFrozenModule"> <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyImport_ImportFrozenModule</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">name</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyImport_ImportFrozenModule" title="Permalink to this definition">¶</a><br /></dt> <dd><p>Load a frozen module named <em>name</em>. Return <code class="docutils literal notranslate"><span class="pre">1</span></code> for success, <code class="docutils literal notranslate"><span class="pre">0</span></code> if the module is not found, and <code class="docutils literal notranslate"><span class="pre">-1</span></code> with an exception set if the initialization failed. To access the imported module on a successful load, use <a class="reference internal" href="#c.PyImport_ImportModule" title="PyImport_ImportModule"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyImport_ImportModule()</span></code></a>. (Note the misnomer — this function would reload the module if it was already imported.)</p> </dd></dl> <dl class="c type"> <dt class="sig sig-object c"> <span class="sig-name descname"><span class="pre">struct</span> <span class="pre">_frozen</span></span></dt> <dd><p id="index-5">This is the structure type definition for frozen module descriptors, as generated by the <strong class="program">freeze</strong> utility (see <code class="file docutils literal notranslate"><span class="pre">Tools/freeze/</span></code> in the Python source distribution). Its definition, found in <code class="file docutils literal notranslate"><span class="pre">Include/import.h</span></code>, is:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">struct</span> <span class="n">_frozen</span> <span class="p">{</span> <span class="n">char</span> <span class="o">*</span><span class="n">name</span><span class="p">;</span> <span class="n">unsigned</span> <span class="n">char</span> <span class="o">*</span><span class="n">code</span><span class="p">;</span> <span class="nb">int</span> <span class="n">size</span><span class="p">;</span> <span class="p">};</span> </pre></div> </div> </dd></dl> <dl class="c var"> <dt class="sig sig-object c" id="c.PyImport_FrozenModules"> <span class="k"><span class="pre">struct</span></span><span class="w"> </span><span class="n"><span class="pre">_frozen</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyImport_FrozenModules</span></span></span><a class="headerlink" href="#c.PyImport_FrozenModules" title="Permalink to this definition">¶</a><br /></dt> <dd><p>This pointer is initialized to point to an array of <code class="xref c c-type docutils literal notranslate"><span class="pre">struct</span> <span class="pre">_frozen</span></code> 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="c function"> <dt class="sig sig-object c" id="c.PyImport_AppendInittab"> <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyImport_AppendInittab</span></span></span><span class="sig-paren">(</span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">name</span></span>, <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="p"><span class="pre">(</span></span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">initfunc</span></span><span class="p"><span class="pre">)</span></span><span class="p"><span class="pre">(</span></span><span class="kt"><span class="pre">void</span></span><span class="p"><span class="pre">)</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyImport_AppendInittab" title="Permalink to this definition">¶</a><br /></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="#c.PyImport_ExtendInittab" title="PyImport_ExtendInittab"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyImport_ExtendInittab()</span></code></a>, returning <code class="docutils literal notranslate"><span class="pre">-1</span></code> 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#c.Py_Initialize" title="Py_Initialize"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_Initialize()</span></code></a>.</p> </dd></dl> <dl class="c type"> <dt class="sig sig-object c"> <span class="sig-name descname"><span class="pre">struct</span> <span class="pre">_inittab</span></span></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="#c.PyImport_ExtendInittab" title="PyImport_ExtendInittab"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyImport_ExtendInittab()</span></code></a> to provide additional built-in modules. The structure is defined in <code class="file docutils literal notranslate"><span class="pre">Include/import.h</span></code> as:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">struct</span> <span class="n">_inittab</span> <span class="p">{</span> <span class="n">char</span> <span class="o">*</span><span class="n">name</span><span class="p">;</span> <span class="n">void</span> <span class="p">(</span><span class="o">*</span><span class="n">initfunc</span><span class="p">)(</span><span class="n">void</span><span class="p">);</span> <span class="p">};</span> </pre></div> </div> </dd></dl> <dl class="c function"> <dt class="sig sig-object c" id="c.PyImport_ExtendInittab"> <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyImport_ExtendInittab</span></span></span><span class="sig-paren">(</span><span class="k"><span class="pre">struct</span></span><span class="w"> </span><span class="n"><span class="pre">_inittab</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">newtab</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyImport_ExtendInittab" title="Permalink to this definition">¶</a><br /></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 <code class="xref py py-attr docutils literal notranslate"><span class="pre">name</span></code> field; failure to provide the sentinel value can result in a memory fault. Returns <code class="docutils literal notranslate"><span class="pre">0</span></code> on success or <code class="docutils literal notranslate"><span class="pre">-1</span></code> 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#c.Py_Initialize" title="Py_Initialize"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_Initialize()</span></code></a>.</p> </dd></dl> </section> <div class="clearer"></div> </div> </div> </div> <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> <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> <div role="note" aria-label="source link"> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../_sources/c-api/import.rst.txt" rel="nofollow">Show Source</a></li> </ul> </div> <div id="searchbox" style="display: none" role="search"> <h3 id="searchlabel">Quick search</h3> <div class="searchformwrapper"> <form class="search" action="../search.html" method="get"> <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/> <input type="submit" value="Go" /> </form> </div> </div> <script>$('#searchbox').show(0);</script> </div> </div> <div class="clearer"></div> </div> <div class="related" role="navigation" aria-label="related navigation"> <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="https://www.python.org/">Python</a> »</li> <li> <a href="../index.html">Python 2.7.18 documentation</a> » </li> <li class="nav-item nav-item-1"><a href="index.html" >Python/C API Reference Manual</a> »</li> <li class="nav-item nav-item-2"><a href="utilities.html" >Utilities</a> »</li> <li class="nav-item nav-item-this"><a href="">Importing Modules</a></li> </ul> </div> <div class="footer"> © <a href="../copyright.html">Copyright</a> 1990-2024, Python Software Foundation. <br /> The Python Software Foundation is a non-profit corporation. <a href="https://www.python.org/psf/donations/">Please donate.</a> <br /> Last updated on December 09, 2024. <a href="../bugs.html">Found a bug</a>? <br /> Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 4.3.2. </div> </body> </html>
Close