332 lines
29 KiB
HTML
332 lines
29 KiB
HTML
|
|
<!DOCTYPE html>
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
|
|
<head>
|
|
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
|
|
|
<title>runpy ——查找并执行 Python 模块 — Python 3.8.20 文档</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
|
|
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
|
|
|
<script id="documentation_options" data-url_root="../" 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/language_data.js"></script>
|
|
<script src="../_static/translations.js"></script>
|
|
|
|
<script src="../_static/sidebar.js"></script>
|
|
|
|
<link rel="search" type="application/opensearchdescription+xml"
|
|
title="在 Python 3.8.20 文档 中搜索"
|
|
href="../_static/opensearch.xml"/>
|
|
<link rel="author" title="关于这些文档" href="../about.html" />
|
|
<link rel="index" title="索引" href="../genindex.html" />
|
|
<link rel="search" title="搜索" href="../search.html" />
|
|
<link rel="copyright" title="版权所有" href="../copyright.html" />
|
|
<link rel="next" title="importlib --- import 的实现" href="importlib.html" />
|
|
<link rel="prev" title="modulefinder --- 查找脚本使用的模块" href="modulefinder.html" />
|
|
<link rel="canonical" href="https://docs.python.org/3/library/runpy.html" />
|
|
|
|
|
|
|
|
|
|
|
|
<style>
|
|
@media only screen {
|
|
table.full-width-table {
|
|
width: 100%;
|
|
}
|
|
}
|
|
</style>
|
|
<link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
|
|
<script type="text/javascript" src="../_static/copybutton.js"></script>
|
|
<script type="text/javascript" src="../_static/menu.js"></script>
|
|
|
|
</head>
|
|
<body>
|
|
<div class="mobile-nav">
|
|
<input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
|
|
aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
|
|
<label for="menuToggler" class="toggler__label">
|
|
<span></span>
|
|
</label>
|
|
<nav class="nav-content" role="navigation">
|
|
<a href="https://www.python.org/" class="nav-logo">
|
|
<img src="../_static/py.svg" alt="Logo"/>
|
|
</a>
|
|
<div class="version_switcher_placeholder"></div>
|
|
<form role="search" class="search" action="../search.html" method="get">
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
|
|
<path fill-rule="nonzero"
|
|
d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z" fill="#444"></path>
|
|
</svg>
|
|
<input type="text" name="q" aria-label="快速搜索"/>
|
|
<input type="submit" value="转向"/>
|
|
</form>
|
|
</nav>
|
|
<div class="menu-wrapper">
|
|
<nav class="menu" role="navigation" aria-label="main navigation">
|
|
<div class="language_switcher_placeholder"></div>
|
|
<h4>上一个主题</h4>
|
|
<p class="topless"><a href="modulefinder.html"
|
|
title="上一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">modulefinder</span></code> --- 查找脚本使用的模块</a></p>
|
|
<h4>下一个主题</h4>
|
|
<p class="topless"><a href="importlib.html"
|
|
title="下一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib</span></code> --- <code class="xref std std-keyword docutils literal notranslate"><span class="pre">import</span></code> 的实现</a></p>
|
|
<div role="note" aria-label="source link">
|
|
<h3>本页</h3>
|
|
<ul class="this-page-menu">
|
|
<li><a href="../bugs.html">报告 Bug</a></li>
|
|
<li>
|
|
<a href="https://github.com/python/cpython/blob/3.8/Doc/library/runpy.rst"
|
|
rel="nofollow">显示源代码
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</nav>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outdated-warning" style="padding: .5em; text-align: center; background-color: #FFBABA; color: #6A0E0E;">
|
|
这个文档所针对的是一个已不再受支持的 Python 旧版本。
|
|
你应当升级版本,并阅读
|
|
<a href="/3/library/runpy.html"> Python 当前稳定版本的文档</a>.
|
|
</div>
|
|
|
|
<div class="related" role="navigation" aria-label="related navigation">
|
|
<h3>导航</h3>
|
|
<ul>
|
|
<li class="right" style="margin-right: 10px">
|
|
<a href="../genindex.html" title="总目录"
|
|
accesskey="I">索引</a></li>
|
|
<li class="right" >
|
|
<a href="../py-modindex.html" title="Python 模块索引"
|
|
>模块</a> |</li>
|
|
<li class="right" >
|
|
<a href="importlib.html" title="importlib --- import 的实现"
|
|
accesskey="N">下一页</a> |</li>
|
|
<li class="right" >
|
|
<a href="modulefinder.html" title="modulefinder --- 查找脚本使用的模块"
|
|
accesskey="P">上一页</a> |</li>
|
|
|
|
<li><img src="../_static/py.svg" alt="python logo" style="vertical-align: middle; margin-top: -1px"/></li>
|
|
<li><a href="https://www.python.org/">Python</a> »</li>
|
|
<li class="switchers">
|
|
<div class="language_switcher_placeholder"></div>
|
|
<div class="version_switcher_placeholder"></div>
|
|
</li>
|
|
<li>
|
|
|
|
</li>
|
|
<li id="cpython-language-and-version">
|
|
<a href="../index.html">3.8.20 Documentation</a> »
|
|
</li>
|
|
|
|
<li class="nav-item nav-item-1"><a href="index.html" >Python 标准库</a> »</li>
|
|
<li class="nav-item nav-item-2"><a href="modules.html" accesskey="U">导入模块</a> »</li>
|
|
<li class="right">
|
|
|
|
|
|
<div class="inline-search" role="search">
|
|
<form class="inline-search" action="../search.html" method="get">
|
|
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
|
|
<input type="submit" value="转向" />
|
|
<input type="hidden" name="check_keywords" value="yes" />
|
|
<input type="hidden" name="area" value="default" />
|
|
</form>
|
|
</div>
|
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="document">
|
|
<div class="documentwrapper">
|
|
<div class="bodywrapper">
|
|
<div class="body" role="main">
|
|
|
|
<section id="module-runpy">
|
|
<span id="runpy-locating-and-executing-python-modules"></span><h1><a class="reference internal" href="#module-runpy" title="runpy: Locate and run Python modules without importing them first."><code class="xref py py-mod docutils literal notranslate"><span class="pre">runpy</span></code></a> ——查找并执行 Python 模块<a class="headerlink" href="#module-runpy" title="永久链接至标题">¶</a></h1>
|
|
<p><strong>源代码:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.8/Lib/runpy.py">Lib/runpy.py</a></p>
|
|
<hr class="docutils" />
|
|
<p><a class="reference internal" href="#module-runpy" title="runpy: Locate and run Python modules without importing them first."><code class="xref py py-mod docutils literal notranslate"><span class="pre">runpy</span></code></a> 模块用于找到并运行 Python 的模块,而无需首先导入。主要用于实现 <a class="reference internal" href="../using/cmdline.html#cmdoption-m"><code class="xref std std-option docutils literal notranslate"><span class="pre">-m</span></code></a> 命令行开关,以允许用 Python 模块命名空间而不是文件系统来定位脚本。</p>
|
|
<p>请注意,这 <em>并非</em> 一个沙盒模块——所有代码都在当前进程中运行,所有副作用(如其他模块对导入操作进行了缓存)在函数返回后都会留存。</p>
|
|
<p>此外,在 <a class="reference internal" href="#module-runpy" title="runpy: Locate and run Python modules without importing them first."><code class="xref py py-mod docutils literal notranslate"><span class="pre">runpy</span></code></a> 函数返回后,任何由已执行代码定义的函数和类都不能保证正确工作。如果某使用场景不能接收此限制,那么选用 <a class="reference internal" href="importlib.html#module-importlib" title="importlib: The implementation of the import machinery."><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib</span></code></a> 可能更合适些。</p>
|
|
<p><a class="reference internal" href="#module-runpy" title="runpy: Locate and run Python modules without importing them first."><code class="xref py py-mod docutils literal notranslate"><span class="pre">runpy</span></code></a> 模块提供两个函数:</p>
|
|
<dl class="function">
|
|
<dt id="runpy.run_module">
|
|
<code class="sig-prename descclassname">runpy.</code><code class="sig-name descname">run_module</code><span class="sig-paren">(</span><em class="sig-param">mod_name</em>, <em class="sig-param">init_globals=None</em>, <em class="sig-param">run_name=None</em>, <em class="sig-param">alter_sys=False</em><span class="sig-paren">)</span><a class="headerlink" href="#runpy.run_module" title="永久链接至目标">¶</a></dt>
|
|
<dd><p id="index-0">执行给定模块的代码,并返回结果模块的 globals 字典。 该模块的代码首先会用标准的导入机制去查找定位 (详情请参阅 <span class="target" id="index-16"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0302"><strong>PEP 302</strong></a>),然后在全新的模块命名空间中运行。</p>
|
|
<p>参数 <em>mod_name</em> 应该是一个绝对模块名。如果模块名指向一个包,而不是普通的模块,那么该包会被导入,然后执行包中的 <code class="docutils literal notranslate"><span class="pre">__main__</span></code> 子模块,并返回结果模块的 globals 字典。</p>
|
|
<p>可选的字典参数 <em>init_globals</em> 可用来在代码执行前预填充模块的 globals 字典。给出的字典参数不会被修改。如果字典中定义了以下任意一个特殊全局变量,这些定义都会被 <a class="reference internal" href="#runpy.run_module" title="runpy.run_module"><code class="xref py py-func docutils literal notranslate"><span class="pre">run_module()</span></code></a> 覆盖。</p>
|
|
<p>The special global variables <code class="docutils literal notranslate"><span class="pre">__name__</span></code>, <code class="docutils literal notranslate"><span class="pre">__spec__</span></code>, <code class="docutils literal notranslate"><span class="pre">__file__</span></code>,
|
|
<code class="docutils literal notranslate"><span class="pre">__cached__</span></code>, <code class="docutils literal notranslate"><span class="pre">__loader__</span></code> and <code class="docutils literal notranslate"><span class="pre">__package__</span></code> are set in the globals
|
|
dictionary before the module code is executed (Note that this is a
|
|
minimal set of variables - other variables may be set implicitly as an
|
|
interpreter implementation detail).</p>
|
|
<p>若可选参数 <code class="docutils literal notranslate"><span class="pre">__name__</span></code> 不为 <a class="reference internal" href="constants.html#None" title="None"><code class="xref py py-const docutils literal notranslate"><span class="pre">None</span></code></a> 则设为 <em>run_name</em>,若此名称的模块是一个包则设为 <code class="docutils literal notranslate"><span class="pre">mod_name</span> <span class="pre">+</span> <span class="pre">'.__main__'</span></code>,否则设为 <em>mod_name</em> 参数。</p>
|
|
<p><code class="docutils literal notranslate"><span class="pre">__spec__</span></code> 将设为合适的 <em>实际</em> 导入模块(也就是说,<code class="docutils literal notranslate"><span class="pre">__spec__.name</span></code> 一定是 <em>mod_name</em> 或 <code class="docutils literal notranslate"><span class="pre">mod_name</span> <span class="pre">+</span> <span class="pre">'.__main__</span></code>,而不是 <em>run_name</em>)。</p>
|
|
<p><code class="docutils literal notranslate"><span class="pre">__file__</span></code> 、<code class="docutils literal notranslate"><span class="pre">__cached__</span></code>、 <code class="docutils literal notranslate"><span class="pre">__loader__</span></code> 和 <code class="docutils literal notranslate"><span class="pre">__package__</span></code> 根据模块规范进行 <a class="reference internal" href="../reference/import.html#import-mod-attrs"><span class="std std-ref">正常设置</span></a></p>
|
|
<p>如果给出了参数 <em>alter_sys</em> 并且值为 <a class="reference internal" href="constants.html#True" title="True"><code class="xref py py-const docutils literal notranslate"><span class="pre">True</span></code></a>,那么 <code class="docutils literal notranslate"><span class="pre">sys.argv[0]</span></code> 将被更新为 <code class="docutils literal notranslate"><span class="pre">__file__</span></code> 的值,<code class="docutils literal notranslate"><span class="pre">sys.modules[__name__]</span></code> 将被更新为临时模块对象。在函数返回前, <code class="docutils literal notranslate"><span class="pre">sys.argv[0]</span></code> 和 <code class="docutils literal notranslate"><span class="pre">sys.modules[__name__]</span></code> 将会复原。</p>
|
|
<p>注意,这种对 <a class="reference internal" href="sys.html#module-sys" title="sys: Access system-specific parameters and functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys</span></code></a> 的操作不是线程安全的。其他线程可能会看到初始化不完整的模块,以及变动后的参数列表。如果从线程中的代码调用此函数,建议单实例运行 <a class="reference internal" href="sys.html#module-sys" title="sys: Access system-specific parameters and functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys</span></code></a> 模块。</p>
|
|
<div class="admonition seealso">
|
|
<p class="admonition-title">参见</p>
|
|
<p><a class="reference internal" href="../using/cmdline.html#cmdoption-m"><code class="xref std std-option docutils literal notranslate"><span class="pre">-m</span></code></a> 选项由命令行提供相同功能。</p>
|
|
</div>
|
|
<div class="versionchanged">
|
|
<p><span class="versionmodified changed">在 3.1 版更改: </span>加入了 查找 <code class="docutils literal notranslate"><span class="pre">__main__</span></code> 子模块并执行软件包的能力。</p>
|
|
</div>
|
|
<div class="versionchanged">
|
|
<p><span class="versionmodified changed">在 3.2 版更改: </span>加入了 <code class="docutils literal notranslate"><span class="pre">__cached__</span></code> 全局变量(参见 <span class="target" id="index-17"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3147"><strong>PEP 3147</strong></a> )。</p>
|
|
</div>
|
|
<div class="versionchanged">
|
|
<p><span class="versionmodified changed">在 3.4 版更改: </span>充分利用 <span class="target" id="index-18"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0451"><strong>PEP 451</strong></a> 加入的模块规格功能。使得以这种方式运行的模块能够正确设置 <code class="docutils literal notranslate"><span class="pre">__cached__</span></code>,并确保真正的模块名称总是可以通过 <code class="docutils literal notranslate"><span class="pre">__spec__.name</span></code> 的形式访问。</p>
|
|
</div>
|
|
</dd></dl>
|
|
|
|
<dl class="function">
|
|
<dt id="runpy.run_path">
|
|
<code class="sig-prename descclassname">runpy.</code><code class="sig-name descname">run_path</code><span class="sig-paren">(</span><em class="sig-param">file_path</em>, <em class="sig-param">init_globals=None</em>, <em class="sig-param">run_name=None</em><span class="sig-paren">)</span><a class="headerlink" href="#runpy.run_path" title="永久链接至目标">¶</a></dt>
|
|
<dd><p id="index-4">执行指定位置的代码,并返回结果模块的 globals 字典。与提供给 CPython 命令行的脚本名称一样,给出的路径可以指向 Python 源文件、编译过的字节码文件或包含``__main__`` 模块的有效 sys.path 项(例如一个包含顶级``__main__.py`` 文件的 zip 文件)。</p>
|
|
<p>对于直接的脚本而言,指定代码将直接在一个新的模块命名空间中运行。对于一个有效的 sys.path 项(通常是一个 zip 文件或目录),其首先会被添加到 <code class="docutils literal notranslate"><span class="pre">sys.path</span></code> 的开头。然后,本函数用更新后的路径查找并执行 <a class="reference internal" href="__main__.html#module-__main__" title="__main__: The environment where the top-level script is run."><code class="xref py py-mod docutils literal notranslate"><span class="pre">__main__</span></code></a> 模块。请注意,即便在指定位置不存在主模块,也没有特别的保护措施来防止调用存在于 <code class="docutils literal notranslate"><span class="pre">sys.path</span></code> 其他地方的 <a class="reference internal" href="__main__.html#module-__main__" title="__main__: The environment where the top-level script is run."><code class="xref py py-mod docutils literal notranslate"><span class="pre">__main__</span></code></a>。</p>
|
|
<p>利用可选的字典参数 <em>init_globals</em> ,可在代码执行前预填模块的 globals 字典。给出的字典参数不会被修改。如果给出的字典中定义了下列特殊全局变量,这些定义均会被 <a class="reference internal" href="#runpy.run_module" title="runpy.run_module"><code class="xref py py-func docutils literal notranslate"><span class="pre">run_module()</span></code></a> 覆盖。</p>
|
|
<p>The special global variables <code class="docutils literal notranslate"><span class="pre">__name__</span></code>, <code class="docutils literal notranslate"><span class="pre">__spec__</span></code>, <code class="docutils literal notranslate"><span class="pre">__file__</span></code>,
|
|
<code class="docutils literal notranslate"><span class="pre">__cached__</span></code>, <code class="docutils literal notranslate"><span class="pre">__loader__</span></code> and <code class="docutils literal notranslate"><span class="pre">__package__</span></code> are set in the globals
|
|
dictionary before the module code is executed (Note that this is a
|
|
minimal set of variables - other variables may be set implicitly as an
|
|
interpreter implementation detail).</p>
|
|
<p>如果该可选参数不为 <a class="reference internal" href="constants.html#None" title="None"><code class="xref py py-const docutils literal notranslate"><span class="pre">None</span></code></a>,则 <code class="docutils literal notranslate"><span class="pre">__name__</span></code> 被设为 <em>run_name</em>,否则为 <code class="docutils literal notranslate"><span class="pre">'<run_path>'</span></code>。</p>
|
|
<p>如果提供的路径直接引用了一个脚本文件(无论是源码文件还是预编译的字节码),那么 <code class="docutils literal notranslate"><span class="pre">__file__</span></code> 将设为给出的路径,而 <code class="docutils literal notranslate"><span class="pre">__spec__</span></code>、<code class="docutils literal notranslate"><span class="pre">__cached__</span></code>、<code class="docutils literal notranslate"><span class="pre">__loader__</span></code> 和 <code class="docutils literal notranslate"><span class="pre">__package__</span></code> 都将设为 <a class="reference internal" href="constants.html#None" title="None"><code class="xref py py-const docutils literal notranslate"><span class="pre">None</span></code></a>。</p>
|
|
<p>如果给出的路径是对有效 sys.path 项的引用,那么 <code class="docutils literal notranslate"><span class="pre">__spec__</span></code> 将为导入的 <code class="docutils literal notranslate"><span class="pre">__main__</span></code> 模块进行正确设置 (也就是说,<code class="docutils literal notranslate"><span class="pre">__spec__.name</span></code> 将一定是 <code class="docutils literal notranslate"><span class="pre">__main__</span></code>)。 <code class="docutils literal notranslate"><span class="pre">__file__</span></code>, <code class="docutils literal notranslate"><span class="pre">__cached__</span></code>, <code class="docutils literal notranslate"><span class="pre">__loader__</span></code> 和 <code class="docutils literal notranslate"><span class="pre">__package__</span></code> 将依据模块规格 <a class="reference internal" href="../reference/import.html#import-mod-attrs"><span class="std std-ref">进行常规设置</span></a>。</p>
|
|
<p><a class="reference internal" href="sys.html#module-sys" title="sys: Access system-specific parameters and functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys</span></code></a> 模块也做了一些改动。 首先,如上所述,<code class="docutils literal notranslate"><span class="pre">sys.path</span></code> 可能会被修改。 <code class="docutils literal notranslate"><span class="pre">sys.argv[0]</span></code> 被更新为 <code class="docutils literal notranslate"><span class="pre">file_path</span></code> 的值,<code class="docutils literal notranslate"><span class="pre">sys.modules[__name__]</span></code> 被更新为正在被执行的模块的临时模块对象。 在函数返回之前,对 <a class="reference internal" href="sys.html#module-sys" title="sys: Access system-specific parameters and functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys</span></code></a> 中条目的所有修改都会被复原。</p>
|
|
<p>注意,与 <a class="reference internal" href="#runpy.run_module" title="runpy.run_module"><code class="xref py py-func docutils literal notranslate"><span class="pre">run_module()</span></code></a> 不同的是,本函数对 <a class="reference internal" href="sys.html#module-sys" title="sys: Access system-specific parameters and functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys</span></code></a> 的修改不是可有可无的,因为这些调整对于 sys.path 项能够顺利执行至关重要。由于依然存在线程安全的限制,在线程代码中使用本函数时应采用导入锁进行序列运行,或者委托给一个单独的进程。</p>
|
|
<div class="admonition seealso">
|
|
<p class="admonition-title">参见</p>
|
|
<p><a class="reference internal" href="../using/cmdline.html#using-on-interface-options"><span class="std std-ref">接口选项</span></a> 用于在命令行上实现同等功能(<code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">path/to/script</span></code>)。</p>
|
|
</div>
|
|
<div class="versionadded">
|
|
<p><span class="versionmodified added">3.2 新版功能.</span></p>
|
|
</div>
|
|
<div class="versionchanged">
|
|
<p><span class="versionmodified changed">在 3.4 版更改: </span>已作更新,以便充分利用 <span class="target" id="index-19"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0451"><strong>PEP 451</strong></a> 加入的模块规格功能。使得从有效 sys.path 项导入``__main__`` 而不是直接执行的情况下,能够正确设置 <code class="docutils literal notranslate"><span class="pre">__cached__</span></code>。</p>
|
|
</div>
|
|
</dd></dl>
|
|
|
|
<div class="admonition seealso">
|
|
<p class="admonition-title">参见</p>
|
|
<dl class="simple">
|
|
<dt><span class="target" id="index-20"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0338"><strong>PEP 338</strong></a> -- 将模块作为脚本执行</dt><dd><p>PEP 由 Nick Coghlan 撰写并实现。</p>
|
|
</dd>
|
|
<dt><span class="target" id="index-21"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0366"><strong>PEP 366</strong></a> ——主模块的显式相对导入</dt><dd><p>PEP 由 Nick Coghlan 撰写并实现。</p>
|
|
</dd>
|
|
<dt><span class="target" id="index-22"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0451"><strong>PEP 451</strong></a> —— 导入系统采用的 ModuleSpec 类型</dt><dd><p>PEP 由 Eric Snow 撰写并实现。</p>
|
|
</dd>
|
|
</dl>
|
|
<p><a class="reference internal" href="../using/cmdline.html#using-on-general"><span class="std std-ref">命令行与环境</span></a> —— CPython 命令行详解</p>
|
|
<p><a class="reference internal" href="importlib.html#importlib.import_module" title="importlib.import_module"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.import_module()</span></code></a> 函数</p>
|
|
</div>
|
|
</section>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
|
<div class="sphinxsidebarwrapper">
|
|
<h4>上一个主题</h4>
|
|
<p class="topless"><a href="modulefinder.html"
|
|
title="上一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">modulefinder</span></code> --- 查找脚本使用的模块</a></p>
|
|
<h4>下一个主题</h4>
|
|
<p class="topless"><a href="importlib.html"
|
|
title="下一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib</span></code> --- <code class="xref std std-keyword docutils literal notranslate"><span class="pre">import</span></code> 的实现</a></p>
|
|
<div role="note" aria-label="source link">
|
|
<h3>本页</h3>
|
|
<ul class="this-page-menu">
|
|
<li><a href="../bugs.html">报告 Bug</a></li>
|
|
<li>
|
|
<a href="https://github.com/python/cpython/blob/3.8/Doc/library/runpy.rst"
|
|
rel="nofollow">显示源代码
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="clearer"></div>
|
|
</div>
|
|
<div class="related" role="navigation" aria-label="related navigation">
|
|
<h3>导航</h3>
|
|
<ul>
|
|
<li class="right" style="margin-right: 10px">
|
|
<a href="../genindex.html" title="总目录"
|
|
>索引</a></li>
|
|
<li class="right" >
|
|
<a href="../py-modindex.html" title="Python 模块索引"
|
|
>模块</a> |</li>
|
|
<li class="right" >
|
|
<a href="importlib.html" title="importlib --- import 的实现"
|
|
>下一页</a> |</li>
|
|
<li class="right" >
|
|
<a href="modulefinder.html" title="modulefinder --- 查找脚本使用的模块"
|
|
>上一页</a> |</li>
|
|
|
|
<li><img src="../_static/py.svg" alt="python logo" style="vertical-align: middle; margin-top: -1px"/></li>
|
|
<li><a href="https://www.python.org/">Python</a> »</li>
|
|
<li class="switchers">
|
|
<div class="language_switcher_placeholder"></div>
|
|
<div class="version_switcher_placeholder"></div>
|
|
</li>
|
|
<li>
|
|
|
|
</li>
|
|
<li id="cpython-language-and-version">
|
|
<a href="../index.html">3.8.20 Documentation</a> »
|
|
</li>
|
|
|
|
<li class="nav-item nav-item-1"><a href="index.html" >Python 标准库</a> »</li>
|
|
<li class="nav-item nav-item-2"><a href="modules.html" >导入模块</a> »</li>
|
|
<li class="right">
|
|
|
|
|
|
<div class="inline-search" role="search">
|
|
<form class="inline-search" action="../search.html" method="get">
|
|
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
|
|
<input type="submit" value="转向" />
|
|
<input type="hidden" name="check_keywords" value="yes" />
|
|
<input type="hidden" name="area" value="default" />
|
|
</form>
|
|
</div>
|
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
</div>
|
|
<div class="footer">
|
|
© <a href="../copyright.html">版权所有</a> 2001-2024, Python Software Foundation.
|
|
<br />
|
|
This page is licensed under the Python Software Foundation License Version 2.
|
|
<br />
|
|
Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
|
|
<br />
|
|
|
|
<br />
|
|
|
|
The Python Software Foundation is a non-profit corporation.
|
|
<a href="https://www.python.org/psf/donations/">Please donate.</a>
|
|
<br />
|
|
<br />
|
|
|
|
最后更新于 12月 09, 2024.
|
|
<a href="https://docs.python.org/3/bugs.html">Found a bug</a>?
|
|
<br />
|
|
|
|
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 2.4.4.
|
|
</div>
|
|
|
|
</body>
|
|
</html> |