📄 86.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Robots" content="INDEX,NOFOLLOW">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<TITLE>Safari | Python Essential Reference, Second Edition -> Module Loading and Compilation</TITLE>
<LINK REL="stylesheet" HREF="oreillyi/oreillyM.css">
</HEAD>
<BODY bgcolor="white" text="black" link="#990000" vlink="#990000" alink="#990000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" cellpadding=5 cellspacing=0 border=0 class="navtopbg"><tr><td><font size="1"><p class="navtitle"><a href="2.html" class="navtitle">Linux/Unix</a> > <a href="0735710910.html" class="navtitle">Python Essential Reference, Second Edition</a> > <a href="82.html" class="navtitle">8. Modules and Packages</a> > <span class="nonavtitle">Module Loading and Compilation</span></p></font></td><td align="right" valign="top" nowrap><font size="1"><a href="main.asp?list" class="safnavoff">See All Titles</a></font></td></tr></table>
<TABLE width=100% bgcolor=white border=0 cellspacing=0 cellpadding=5><TR><TD>
<TABLE border=0 width="100%" cellspacing=0 cellpadding=0><TR><td align=left width="15%" class="headingsubbarbg"><a href="85.html" title="The Module Search Path"><font size="1">< BACK</font></a></td><td align=center width="70%" class="headingsubbarbg"><font size="1"><a href="popanote.asp?pubui=oreilly&bookname=0735710910&snode=86" target="_blank" title="Make a public or private annnotation">Make Note</a> | <a href="86.html" title="Use a Safari bookmark to remember this section">Bookmark</a></font></td><td align=right width="15%" class="headingsubbarbg"><a href="87.html" title="Module Reloading"><font size="1">CONTINUE ></font></a></td></TR></TABLE>
<a href="5%2F28%2F2002+9%3A02%3A02+PM.html" TABINDEX="-1"><img src=images/spacer.gif border=0 width=1 height=1></a><font color=white size=1>155117184014003188065099048180054212144238241179195140058238111161105084124003001139038249</font><a href="read4.asp?bookname=0735710910&snode=86&now=5%2F28%2F2002+9%3A02%3A02+PM" TABINDEX="-1"><img src=images/spacer.gif border=0 width=1 height=1></a><br>
<FONT>
<h3>Module Loading and Compilation</h3>
<p>So far, this chapter has presented modules as files containing Python code. However, modules loaded with <tT CLAss="monofont">import</tt> really fall into four general categories:</P>
<UL>
<Li>
<p>Programs written in Python (<tt CLASs="monofont">.py</tt> files)</p>
</li>
<li>
<p>C or C++ extensions that have been compiled into shared libraries or DLLs</p>
</li>
<li>
<p>Packages containing a collection of modules</p>
</li>
<li>
<P>Built-in modules written in C and linked into the Python interpreter</p>
</lI>
</ul>
<p>When looking for a module <Tt claSs="monofont">foo</tt>, the interpreter searches each of the directories in <TT CLass="monofont">sys.path</tT> for the following files (listed in search order):</P>
<OL type="1">
<LI>
<P> A directory <Tt claSS="monofont">foo</TT> defining a package</p>
</li>
<li>
<p> <tt class="monofont">foo.so</tt>, <tt claSs="monofont">foomodule.so</tT>, <tt cLass="monofont">foomodule.sl</tT>, or <tt cLASS="monofont">foomodule.dll</tt> (compiled extensions)</p>
</lI>
<LI>
<P> <tt clASS="monofont">foo.pyo</Tt> (only if the <tt cLASS="monofont">-O</tt> or <tt class="monofont">-OO</tt> option has been used)</p>
</li>
<li>
<p> <tt cLasS="monofont">foo.pyc</tt></p>
</Li>
<li>
<p> <Tt clASS="monofont">foo.py</Tt></p>
</li>
</OL>
<P>Packages are described shortly; compiled extensions are described in <A href="121.html">Appendix B</A>, 揈xtending and Embedding Python.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -