Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / src / nas,5.n2.os.2 / lib / python / html / python / lib / zipfile-objects.html
CommitLineData
86530b38
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="pyzipfile-objects.html" />
13<link rel="prev" href="module-zipfile.html" />
14<link rel="parent" href="module-zipfile.html" />
15<link rel="next" href="pyzipfile-objects.html" />
16<meta name='aesop' content='information' />
17<title>7.18.1 ZipFile Objects </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="7.18 zipfile "
25 href="module-zipfile.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="7.18 zipfile "
28 href="module-zipfile.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="7.18.2 PyZipFile Objects"
31 href="pyzipfile-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="module-zipfile.html">7.18 zipfile </A>
46<b class="navlabel">Up:</b>
47<a class="sectref" rel="parent" href="module-zipfile.html">7.18 zipfile </A>
48<b class="navlabel">Next:</b>
49<a class="sectref" rel="next" href="pyzipfile-objects.html">7.18.2 PyZipFile Objects</A>
50</div>
51<hr /></div>
52</DIV>
53<!--End of Navigation Panel-->
54
55<H2><A NAME="SECTION0091810000000000000000"></A><A NAME="zipfile-objects"></A>
56<BR>
577.18.1 ZipFile Objects
58</H2>
59
60<P>
61<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
62 <td><nobr><b><span class="typelabel">class</span>&nbsp;<tt id='l2h-2858' xml:id='l2h-2858' class="class">ZipFile</tt></b>(</nobr></td>
63 <td><var>file</var><big>[</big><var>, mode</var><big>[</big><var>, compression</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
64<dd>
65 Open a ZIP file, where <var>file</var> can be either a path to a file
66 (a string) or a file-like object. The <var>mode</var> parameter
67 should be <code>'r'</code> to read an existing file, <code>'w'</code> to
68 truncate and write a new file, or <code>'a'</code> to append to an
69 existing file. For <var>mode</var> is <code>'a'</code> and <var>file</var>
70 refers to an existing ZIP file, then additional files are added to
71 it. If <var>file</var> does not refer to a ZIP file, then a new ZIP
72 archive is appended to the file. This is meant for adding a ZIP
73 archive to another file, such as <span class="file">python.exe</span>. Using
74
75<P>
76<div class="verbatim"><pre>
77cat myzip.zip &gt;&gt; python.exe
78</pre></div>
79
80<P>
81also works, and at least <b class="program">WinZip</b> can read such files.
82 <var>compression</var> is the ZIP compression method to use when writing
83 the archive, and should be <tt class="constant">ZIP_STORED</tt> or
84 <tt class="constant">ZIP_DEFLATED</tt>; unrecognized values will cause
85 <tt class="exception">RuntimeError</tt> to be raised. If <tt class="constant">ZIP_DEFLATED</tt>
86 is specified but the <tt class="module"><a href="module-zlib.html">zlib</a></tt> module is not available,
87 <tt class="exception">RuntimeError</tt> is also raised. The default is
88 <tt class="constant">ZIP_STORED</tt>.
89</dl>
90
91<P>
92<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
93 <td><nobr><b><tt id='l2h-2859' xml:id='l2h-2859' class="method">close</tt></b>(</nobr></td>
94 <td><var></var>)</td></tr></table></dt>
95<dd>
96 Close the archive file. You must call <tt class="method">close()</tt> before
97 exiting your program or essential records will not be written.
98</dl>
99
100<P>
101<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
102 <td><nobr><b><tt id='l2h-2860' xml:id='l2h-2860' class="method">getinfo</tt></b>(</nobr></td>
103 <td><var>name</var>)</td></tr></table></dt>
104<dd>
105 Return a <tt class="class">ZipInfo</tt> object with information about the archive
106 member <var>name</var>.
107</dl>
108
109<P>
110<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
111 <td><nobr><b><tt id='l2h-2861' xml:id='l2h-2861' class="method">infolist</tt></b>(</nobr></td>
112 <td><var></var>)</td></tr></table></dt>
113<dd>
114 Return a list containing a <tt class="class">ZipInfo</tt> object for each member of
115 the archive. The objects are in the same order as their entries in
116 the actual ZIP file on disk if an existing archive was opened.
117</dl>
118
119<P>
120<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
121 <td><nobr><b><tt id='l2h-2862' xml:id='l2h-2862' class="method">namelist</tt></b>(</nobr></td>
122 <td><var></var>)</td></tr></table></dt>
123<dd>
124 Return a list of archive members by name.
125</dl>
126
127<P>
128<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
129 <td><nobr><b><tt id='l2h-2863' xml:id='l2h-2863' class="method">printdir</tt></b>(</nobr></td>
130 <td><var></var>)</td></tr></table></dt>
131<dd>
132 Print a table of contents for the archive to <code>sys.stdout</code>.
133</dl>
134
135<P>
136<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
137 <td><nobr><b><tt id='l2h-2864' xml:id='l2h-2864' class="method">read</tt></b>(</nobr></td>
138 <td><var>name</var>)</td></tr></table></dt>
139<dd>
140 Return the bytes of the file in the archive. The archive must be
141 open for read or append.
142</dl>
143
144<P>
145<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
146 <td><nobr><b><tt id='l2h-2865' xml:id='l2h-2865' class="method">testzip</tt></b>(</nobr></td>
147 <td><var></var>)</td></tr></table></dt>
148<dd>
149 Read all the files in the archive and check their CRC's. Return the
150 name of the first bad file, or else return <code>None</code>.
151</dl>
152
153<P>
154<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
155 <td><nobr><b><tt id='l2h-2866' xml:id='l2h-2866' class="method">write</tt></b>(</nobr></td>
156 <td><var>filename</var><big>[</big><var>, arcname</var><big>[</big><var>,
157 compress_type</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
158<dd>
159 Write the file named <var>filename</var> to the archive, giving it the
160 archive name <var>arcname</var> (by default, this will be the same as
161 <var>filename</var>). If given, <var>compress_type</var> overrides the value
162 given for the <var>compression</var> parameter to the constructor for
163 the new entry. The archive must be open with mode <code>'w'</code> or
164 <code>'a'</code>.
165</dl>
166
167<P>
168<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
169 <td><nobr><b><tt id='l2h-2867' xml:id='l2h-2867' class="method">writestr</tt></b>(</nobr></td>
170 <td><var>zinfo_or_arcname, bytes</var>)</td></tr></table></dt>
171<dd>
172 Write the string <var>bytes</var> to the archive; <var>zinfo_or_arcname</var>
173 is either the file name it will be given in the archive, or a
174 <tt class="class">ZipInfo</tt> instance. If it's an instance, at least the
175 filename, date, and time must be given. If it's a name, the date
176 and time is set to the current date and time. The archive must be
177 opened with mode <code>'w'</code> or <code>'a'</code>.
178</dl>
179
180<P>
181The following data attribute is also available:
182
183<P>
184<dl><dt><b><tt id='l2h-2868' xml:id='l2h-2868' class="member">debug</tt></b></dt>
185<dd>
186 The level of debug output to use. This may be set from <code>0</code>
187 (the default, no output) to <code>3</code> (the most output). Debugging
188 information is written to <code>sys.stdout</code>.
189</dl>
190
191<P>
192
193<DIV CLASS="navigation">
194<div class='online-navigation'>
195<p></p><hr />
196<table align="center" width="100%" cellpadding="0" cellspacing="2">
197<tr>
198<td class='online-navigation'><a rel="prev" title="7.18 zipfile "
199 href="module-zipfile.html"><img src='../icons/previous.png'
200 border='0' height='32' alt='Previous Page' width='32' /></A></td>
201<td class='online-navigation'><a rel="parent" title="7.18 zipfile "
202 href="module-zipfile.html"><img src='../icons/up.png'
203 border='0' height='32' alt='Up One Level' width='32' /></A></td>
204<td class='online-navigation'><a rel="next" title="7.18.2 PyZipFile Objects"
205 href="pyzipfile-objects.html"><img src='../icons/next.png'
206 border='0' height='32' alt='Next Page' width='32' /></A></td>
207<td align="center" width="100%">Python Library Reference</td>
208<td class='online-navigation'><a rel="contents" title="Table of Contents"
209 href="contents.html"><img src='../icons/contents.png'
210 border='0' height='32' alt='Contents' width='32' /></A></td>
211<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
212 border='0' height='32' alt='Module Index' width='32' /></a></td>
213<td class='online-navigation'><a rel="index" title="Index"
214 href="genindex.html"><img src='../icons/index.png'
215 border='0' height='32' alt='Index' width='32' /></A></td>
216</tr></table>
217<div class='online-navigation'>
218<b class="navlabel">Previous:</b>
219<a class="sectref" rel="prev" href="module-zipfile.html">7.18 zipfile </A>
220<b class="navlabel">Up:</b>
221<a class="sectref" rel="parent" href="module-zipfile.html">7.18 zipfile </A>
222<b class="navlabel">Next:</b>
223<a class="sectref" rel="next" href="pyzipfile-objects.html">7.18.2 PyZipFile Objects</A>
224</div>
225</div>
226<hr />
227<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
228</DIV>
229<!--End of Navigation Panel-->
230<ADDRESS>
231See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
232</ADDRESS>
233</BODY>
234</HTML>