Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / html / python / lib / module-zipimport.html
CommitLineData
920dae64
AT
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<html>
3<head>
4<link rel="STYLESHEET" href="lib.css" type='text/css' />
5<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
6<link rel='start' href='../index.html' title='Python Documentation Index' />
7<link rel="first" href="lib.html" title='Python Library Reference' />
8<link rel='contents' href='contents.html' title="Contents" />
9<link rel='index' href='genindex.html' title='Index' />
10<link rel='last' href='about.html' title='About this document...' />
11<link rel='help' href='about.html' title='About this document...' />
12<link rel="next" href="module-pkgutil.html" />
13<link rel="prev" href="module-imp.html" />
14<link rel="parent" href="python.html" />
15<link rel="next" href="zipimporter-objects.html" />
16<meta name='aesop' content='information' />
17<title>3.22 zipimport -- Import modules from Zip archives</title>
18</head>
19<body>
20<DIV CLASS="navigation">
21<div id='top-navigation-panel' xml:id='top-navigation-panel'>
22<table align="center" width="100%" cellpadding="0" cellspacing="2">
23<tr>
24<td class='online-navigation'><a rel="prev" title="3.21.1 Examples"
25 href="examples-imp.html"><img src='../icons/previous.png'
26 border='0' height='32' alt='Previous Page' width='32' /></A></td>
27<td class='online-navigation'><a rel="parent" title="3. Python Runtime Services"
28 href="python.html"><img src='../icons/up.png'
29 border='0' height='32' alt='Up One Level' width='32' /></A></td>
30<td class='online-navigation'><a rel="next" title="3.22.1 zipimporter Objects"
31 href="zipimporter-objects.html"><img src='../icons/next.png'
32 border='0' height='32' alt='Next Page' width='32' /></A></td>
33<td align="center" width="100%">Python Library Reference</td>
34<td class='online-navigation'><a rel="contents" title="Table of Contents"
35 href="contents.html"><img src='../icons/contents.png'
36 border='0' height='32' alt='Contents' width='32' /></A></td>
37<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
38 border='0' height='32' alt='Module Index' width='32' /></a></td>
39<td class='online-navigation'><a rel="index" title="Index"
40 href="genindex.html"><img src='../icons/index.png'
41 border='0' height='32' alt='Index' width='32' /></A></td>
42</tr></table>
43<div class='online-navigation'>
44<b class="navlabel">Previous:</b>
45<a class="sectref" rel="prev" href="examples-imp.html">3.21.1 Examples</A>
46<b class="navlabel">Up:</b>
47<a class="sectref" rel="parent" href="python.html">3. Python Runtime Services</A>
48<b class="navlabel">Next:</b>
49<a class="sectref" rel="next" href="zipimporter-objects.html">3.22.1 zipimporter Objects</A>
50</div>
51<hr /></div>
52</DIV>
53<!--End of Navigation Panel-->
54
55<H1><A NAME="SECTION0052200000000000000000">
563.22 <tt class="module">zipimport</tt> --\r
57 Import modules from Zip archives</A>
58</H1>
59
60<P>
61<A NAME="module-zipimport"></A>
62
63<P>
64
65<span class="versionnote">New in version 2.3.</span>
66
67<P>
68This module adds the ability to import Python modules (<span class="file">*.py</span>,\r
69<span class="file">*.py[co]</span>) and packages from ZIP-format archives. It is usually\r
70not needed to use the <tt class="module">zipimport</tt> module explicitly; it is\r
71automatically used by the builtin <tt class="keyword">import</tt> mechanism for\r
72<code>sys.path</code> items that are paths to ZIP archives.
73
74<P>
75Typically, <code>sys.path</code> is a list of directory names as strings. This\r
76module also allows an item of <code>sys.path</code> to be a string naming a ZIP\r
77file archive. The ZIP archive can contain a subdirectory structure to\r
78support package imports, and a path within the archive can be specified to\r
79only import from a subdirectory. For example, the path\r
80<span class="file">/tmp/example.zip/lib/</span> would only import from the\r
81<span class="file">lib/</span> subdirectory within the archive.
82
83<P>
84Any files may be present in the ZIP archive, but only files <span class="file">.py</span> and\r
85<span class="file">.py[co]</span> are available for import. ZIP import of dynamic modules\r
86(<span class="file">.pyd</span>, <span class="file">.so</span>) is disallowed. Note that if an archive only\r
87contains <span class="file">.py</span> files, Python will not attempt to modify the archive\r
88by adding the corresponding <span class="file">.pyc</span> or <span class="file">.pyo</span> file, meaning that\r
89if a ZIP archive doesn't contain <span class="file">.pyc</span> files, importing may be rather\r
90slow.
91
92<P>
93Using the built-in <tt class="function">reload()</tt> function will\r
94fail if called on a module loaded from a ZIP archive; it is unlikely that\r
95<tt class="function">reload()</tt> would be needed, since this would imply that the ZIP\r
96has been altered during runtime.
97
98<P>
99The available attributes of this module are:
100
101<P>
102<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-726' xml:id='l2h-726' class="exception">ZipImporterError</tt></b></dt>
103<dd>\r
104 Exception raised by zipimporter objects. It's a subclass of\r
105 <tt class="exception">ImportError</tt>, so it can be caught as <tt class="exception">ImportError</tt>,\r
106 too.\r
107</dd></dl>
108
109<P>
110<dl><dt><b><span class="typelabel">class</span>&nbsp;<tt id='l2h-727' xml:id='l2h-727' class="class">zipimporter</tt></b>
111<dd>\r
112 The class for importing ZIP files. See\r
113 ``<em class="citetitle"
114 >zipimporter Objects</em>'' (section <A href="zipimporter-objects.html#zipimporter-objects">3.22.1</A>)\r
115 for constructor details.\r
116</dl>
117
118<P>
119<div class="seealso">
120 <p class="heading">See Also:</p>
121\r
122 <dl compact="compact" class="seetitle">
123 <dt><em class="citetitle"><a href="http://www.pkware.com/appnote.html"
124 >PKZIP Application\r
125 Note</a></em></dt>
126 <dd>Documentation on the ZIP file format by Phil\r
127 Katz, the creator of the format and algorithms used.</dd>
128 </dl>
129
130<P>
131<dl compact="compact" class="seerfc">
132 <dt><a href="http://www.python.org/peps/pep-0273.html"
133 title="Import Modules from Zip Archives"
134 >PEP 0273, <em>Import Modules from Zip Archives</em></a>
135 <dd>Written by James C.\r
136 Ahlstrom, who also provided an implementation. Python 2.3\r
137 follows the specification in PEP 273, but uses an\r
138 implementation written by Just van Rossum that uses the import\r
139 hooks described in PEP 302.
140 </dl>
141
142<P>
143<dl compact="compact" class="seerfc">
144 <dt><a href="http://www.python.org/peps/pep-0302.html"
145 title="New Import Hooks"
146 >PEP 0302, <em>New Import Hooks</em></a>
147 <dd>The PEP to add the import hooks that help\r
148 this module work.
149 </dl>\r
150</div>
151
152<P>
153
154<p><br /></p><hr class='online-navigation' />
155<div class='online-navigation'>
156<!--Table of Child-Links-->
157<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></a>
158
159<UL CLASS="ChildLinks">
160<LI><A href="zipimporter-objects.html">3.22.1 zipimporter Objects</a>
161<LI><A href="node88.html">3.22.2 Examples</a>
162</ul>
163<!--End of Table of Child-Links-->
164</div>
165
166<DIV CLASS="navigation">
167<div class='online-navigation'>
168<p></p><hr />
169<table align="center" width="100%" cellpadding="0" cellspacing="2">
170<tr>
171<td class='online-navigation'><a rel="prev" title="3.21.1 Examples"
172 href="examples-imp.html"><img src='../icons/previous.png'
173 border='0' height='32' alt='Previous Page' width='32' /></A></td>
174<td class='online-navigation'><a rel="parent" title="3. Python Runtime Services"
175 href="python.html"><img src='../icons/up.png'
176 border='0' height='32' alt='Up One Level' width='32' /></A></td>
177<td class='online-navigation'><a rel="next" title="3.22.1 zipimporter Objects"
178 href="zipimporter-objects.html"><img src='../icons/next.png'
179 border='0' height='32' alt='Next Page' width='32' /></A></td>
180<td align="center" width="100%">Python Library Reference</td>
181<td class='online-navigation'><a rel="contents" title="Table of Contents"
182 href="contents.html"><img src='../icons/contents.png'
183 border='0' height='32' alt='Contents' width='32' /></A></td>
184<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
185 border='0' height='32' alt='Module Index' width='32' /></a></td>
186<td class='online-navigation'><a rel="index" title="Index"
187 href="genindex.html"><img src='../icons/index.png'
188 border='0' height='32' alt='Index' width='32' /></A></td>
189</tr></table>
190<div class='online-navigation'>
191<b class="navlabel">Previous:</b>
192<a class="sectref" rel="prev" href="examples-imp.html">3.21.1 Examples</A>
193<b class="navlabel">Up:</b>
194<a class="sectref" rel="parent" href="python.html">3. Python Runtime Services</A>
195<b class="navlabel">Next:</b>
196<a class="sectref" rel="next" href="zipimporter-objects.html">3.22.1 zipimporter Objects</A>
197</div>
198</div>
199<hr />
200<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
201</DIV>
202<!--End of Navigation Panel-->
203<ADDRESS>
204See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
205</ADDRESS>
206</BODY>
207</HTML>