📄 module-zipfile.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>7.16 zipfile -- Work with ZIP archives</title>
<META NAME="description" CONTENT="7.16 zipfile -- Work with ZIP archives">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="lib.css" tppabs="http://www.python.org/doc/current/lib/lib.css">
<LINK REL="next" href="module-readline.html" tppabs="http://www.python.org/doc/current/lib/module-readline.html">
<LINK REL="previous" href="module-gzip.html" tppabs="http://www.python.org/doc/current/lib/module-gzip.html">
<LINK REL="up" href="someos.html" tppabs="http://www.python.org/doc/current/lib/someos.html">
<LINK REL="next" href="zipfile-objects.html" tppabs="http://www.python.org/doc/current/lib/zipfile-objects.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-gzip.html" tppabs="http://www.python.org/doc/current/lib/module-gzip.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A href="someos.html" tppabs="http://www.python.org/doc/current/lib/someos.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A href="zipfile-objects.html" tppabs="http://www.python.org/doc/current/lib/zipfile-objects.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="module-gzip.html" tppabs="http://www.python.org/doc/current/lib/module-gzip.html">7.15 gzip </A>
<b class="navlabel">Up:</b> <a class="sectref" href="someos.html" tppabs="http://www.python.org/doc/current/lib/someos.html">7. Optional Operating System</A>
<b class="navlabel">Next:</b> <a class="sectref" href="zipfile-objects.html" tppabs="http://www.python.org/doc/current/lib/zipfile-objects.html">7.16.1 ZipFile Objects</A>
<br><hr></DIV>
<!--End of Navigation Panel-->
<H1><A NAME="SECTION0091600000000000000000">
7.16 <tt class="module">zipfile</tt> --
Work with ZIP archives</A>
</H1>
<P>
<P>
New in version 1.6.
<P>
The ZIP file format is a common archive and compression standard.
This module provides tools to create, read, write, append, and list a
ZIP file. Any advanced use of this module will require an
understanding of the format, as defined in
<em class='citetitle'><a
href="javascript:if(confirm('http://www.pkware.com/appnote.html \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.pkware.com/appnote.html'" tppabs="http://www.pkware.com/appnote.html"
title='PKZIP Application
Note'
>PKZIP Application
Note <img src="offsite.gif" tppabs="http://www.python.org/doc/current/icons/offsite.gif"
border='0' class='offsitelink' height='15' width='17' alt='[off-site link]'
></a></em>.
<P>
This module does not currently handle ZIP files which have appended
comments, or multi-disk ZIP files.
<P>
The available attributes of this module are:
<P>
<dl><dt><b><a name='l2h-1756'><tt class='exception'>error</tt></a></b>
<dd>
The error raised for bad ZIP files.
</dl>
<P>
<dl><dt><b><a name='l2h-1757'><tt class='class'>ZipFile</tt></a></b> (<var>...</var>)
<dd>
The class for reading and writing ZIP files. See
``<em class='citetitle'
>ZipFile Objects</em>'' (section <A href="zipfile-objects.html#zipfile-objects" tppabs="http://www.python.org/doc/current/lib/zipfile-objects.html#zipfile-objects">7.16.1</A>) for
constructor details.
</dl>
<P>
<dl><dt><b><a name='l2h-1758'><tt class='class'>PyZipFile</tt></a></b> (<var>...</var>)
<dd>
Class for creating ZIP archives containing Python libraries.
</dl>
<P>
<dl><dt><b><a name='l2h-1759'><tt class='class'>ZipInfo</tt></a></b> (<big>[</big><var>filename</var><big>[</big><var>, date_time</var><big>]</big><big>]</big>)
<dd>
Class used the represent infomation about a member of an archive.
Instances of this class are returned by the <tt class="method">getinfo()</tt> and
<tt class="method">infolist()</tt> methods of <tt class="class">ZipFile</tt> objects. Most users
of the <tt class="module">zipfile</tt> module will not need to create these, but
only use those created by this module.
<var>filename</var> should be the full name of the archive member, and
<var>date_time</var> should be a tuple containing six fields which
describe the time of the last modification to the file; the fields
are described in section <A href="zipinfo-objects.html#zipinfo-objects" tppabs="http://www.python.org/doc/current/lib/zipinfo-objects.html#zipinfo-objects">7.16.3</A>, ``ZipInfo Objects.''
</dl>
<P>
<dl><dt><b><a name='l2h-1760'><tt class='function'>is_zipfile</tt></a></b> (<var>filename</var>)
<dd>
Returns true if <var>filename</var> is a valid ZIP file based on its magic
number, otherwise returns false. This module does not currently
handle ZIP files which have appended comments.
</dl>
<P>
<dl><dt><b><a name='l2h-1761'><tt>ZIP_STORED</tt></a></b>
<dd>
The numeric constant for an uncompressed archive member.
</dl>
<P>
<dl><dt><b><a name='l2h-1762'><tt>ZIP_DEFLATED</tt></a></b>
<dd>
The numeric constant for the usual ZIP compression method. This
requires the zlib module. No other compression methods are
currently supported.
</dl>
<P>
<div class='seealso'>
<p class='heading'><b>See Also:</b></p>
<dl compact class="seetitle">
<dt><em class="citetitle"><a href="javascript:if(confirm('http://www.pkware.com/appnote.html \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.pkware.com/appnote.html'" tppabs="http://www.pkware.com/appnote.html"
>PKZIP Application
Note <img src="offsite.gif" tppabs="http://www.python.org/doc/current/icons/offsite.gif"
border='0' class='offsitelink' height='15' width='17' alt='[off-site link]'
></a></em>
<dd>Documentation on the ZIP file format by Phil
Katz, the creator of the format and algorithms used.
</dl>
<P>
<dl compact class="seetitle">
<dt><em class="citetitle"><a href="javascript:if(confirm('http://www.info-zip.org/pub/infozip/ \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.info-zip.org/pub/infozip/'" tppabs="http://www.info-zip.org/pub/infozip/"
>Info-ZIP Home Page <img src="offsite.gif" tppabs="http://www.python.org/doc/current/icons/offsite.gif"
border='0' class='offsitelink' height='15' width='17' alt='[off-site link]'
></a></em>
<dd>
Information about the Info-ZIP project's ZIP archive
programs and development libraries.
</dl>
</div>
<P>
<p><hr>
<!--Table of Child-Links-->
<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></A>
<UL>
<LI><A NAME="tex2html3158"
href="zipfile-objects.html" tppabs="http://www.python.org/doc/current/lib/zipfile-objects.html">7.16.1 ZipFile Objects </A>
<LI><A NAME="tex2html3159"
href="pyzipfile-objects.html" tppabs="http://www.python.org/doc/current/lib/pyzipfile-objects.html">7.16.2 PyZipFile Objects </A>
<LI><A NAME="tex2html3160"
href="zipinfo-objects.html" tppabs="http://www.python.org/doc/current/lib/zipinfo-objects.html">7.16.3 ZipInfo Objects </A>
</UL>
<!--End of Table of Child-Links-->
<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-gzip.html" tppabs="http://www.python.org/doc/current/lib/module-gzip.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A href="someos.html" tppabs="http://www.python.org/doc/current/lib/someos.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A href="zipfile-objects.html" tppabs="http://www.python.org/doc/current/lib/zipfile-objects.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="module-gzip.html" tppabs="http://www.python.org/doc/current/lib/module-gzip.html">7.15 gzip </A>
<b class="navlabel">Up:</b> <a class="sectref" href="someos.html" tppabs="http://www.python.org/doc/current/lib/someos.html">7. Optional Operating System</A>
<b class="navlabel">Next:</b> <a class="sectref" href="zipfile-objects.html" tppabs="http://www.python.org/doc/current/lib/zipfile-objects.html">7.16.1 ZipFile Objects</A>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>See <i><a href="about.html" tppabs="http://www.python.org/doc/current/lib/about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -