zipfile.ZipFile解压文件

简介:
class ZipFile(builtins.object)
 |  Class with methods to open, read, write, close, list zip files.
 |  
 |  z = ZipFile(file, mode="r", compression=ZIP_STORED, allowZip64=True)
 |  
 |  file: Either the path to the file, or a file-like object.
 |        If it is a path, the file will be opened and closed by ZipFile.
 |  mode: The mode can be either read 'r', write 'w', exclusive create 'x',
 |        or append 'a'.
 |  compression: ZIP_STORED (no compression), ZIP_DEFLATED (requires zlib),
 |               ZIP_BZIP2 (requires bz2) or ZIP_LZMA (requires lzma).
 |  allowZip64: if True ZipFile will create files with ZIP64 extensions when
 |              needed, otherwise it will raise an exception when this would
 |              be necessary.
 |  
 |  Methods defined here:
 |  
 |  __del__(self)
 |      Call the "close()" method in case the user forgot.
 |  
 |  __enter__(self)
 |  
 |  __exit__(self, type, value, traceback)
 |  
 |  __init__(self, file, mode='r', compression=0, allowZip64=True)
 |      Open the ZIP file with mode read 'r', write 'w', exclusive create 'x',
 |      or append 'a'.
 |  
 |  __repr__(self)
 |      Return repr(self).
 |  
 |  close(self)
 |      Close the file, and for mode 'w', 'x' and 'a' write the ending
 |      records.
 |  
 |  extract(self, member, path=None, pwd=None)
 |      Extract a member from the archive to the current working directory,
 |      using its full name. Its file information is extracted as accurately
 |      as possible. `member' may be a filename or a ZipInfo object. You can
 |      specify a different directory using `path'.
 |  
 |  extractall(self, path=None, members=None, pwd=None)
 |      Extract all members from the archive to the current working
 |      directory. `path' specifies a different directory to extract to.
 |      `members' is optional and must be a subset of the list returned
 |      by namelist().
 |  
 |  getinfo(self, name)
 |      Return the instance of ZipInfo given 'name'.
 |  
 |  infolist(self)
 |      Return a list of class ZipInfo instances for files in the
 |      archive.
 |  
 |  namelist(self)
 |      Return a list of file names in the archive.
 |  
 |  open(self, name, mode='r', pwd=None, *, force_zip64=False)
 |      Return file-like object for 'name'.
 |      
 |      name is a string for the file name within the ZIP file, or a ZipInfo
 |      object.
 |      
 |      mode should be 'r' to read a file already in the ZIP file, or 'w' to
 |      write to a file newly added to the archive.
 |      
 |      pwd is the password to decrypt files (only used for reading).
 |      
 |      When writing, if the file size is not known in advance but may exceed
 |      2 GiB, pass force_zip64 to use the ZIP64 format, which can handle large
 |      files.  If the size is known in advance, it is best to pass a ZipInfo
 |      instance for name, with zinfo.file_size set.
 |  
 |  printdir(self, file=None)
 |      Print a table of contents for the zip file.
 |  
 |  read(self, name, pwd=None)
 |      Return file bytes (as a string) for name.
 |  
 |  setpassword(self, pwd)
 |      Set default password for encrypted files.
 |  
 |  testzip(self)
 |      Read all the files and check the CRC.
 |  
 |  write(self, filename, arcname=None, compress_type=None)
 |      Put the bytes from filename into the archive under the name
 |      arcname.
 |  
 |  writestr(self, zinfo_or_arcname, data, compress_type=None)
 |      Write a file into the archive.  The contents is 'data', which
 |      may be either a 'str' or a 'bytes' instance; if it is a 'str',
 |      it is encoded as UTF-8 first.
 |      'zinfo_or_arcname' is either a ZipInfo instance or
 |      the name of the file in the archive.
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |  
 |  __dict__
 |      dictionary for instance variables (if defined)
 |  
 |  __weakref__
 |      list of weak references to the object (if defined)
 |  
 |  comment
 |      The comment text associated with the ZIP file.
 |  
 |  ----------------------------------------------------------------------
 |  Data and other attributes defined here:
 |  
 |  fp = None
目录
相关文章
|
1月前
|
Python
Zipfile学习笔记(一):通过zipfile模块实现文件的压缩和解压
使用Python的zipfile模块来实现文件的压缩和解压,通过具体代码示例展示了压缩和解压的过程。
79 2
Zipfile学习笔记(一):通过zipfile模块实现文件的压缩和解压
|
27天前
|
Unix Linux
unzip 解压文件到指定目录,如何操作?
【10月更文挑战第20天】unzip 解压文件到指定目录,如何操作?
435 2
zipfile.BadZipFile: File is not a zip file|4-21
zipfile.BadZipFile: File is not a zip file|4-21
zipfile.BadZipFile: File is not a zip file|4-21
|
2月前
|
存储 Unix Python
shutil:更优雅地拷贝文件
shutil:更优雅地拷贝文件
41 0
|
6月前
|
计算机视觉 Python
zip
zip
43 2
|
6月前
|
存储 Linux 数据安全/隐私保护
|
6月前
|
存储 数据安全/隐私保护 Windows
7-Zip 的使用技巧
7-Zip 的使用技巧
|
算法
ZIP和RAR文件的不同
生活中我们经常需要使用电脑与朋友之间的文件传送,但往往会受到文件大小的限制而无法发出去,此时需要将文件压缩后再发送,那么有小伙伴会问rar和zip又有什么区别?
547 0
ZIP和RAR文件的不同
|
Unix Linux Shell
Shell - 常用压缩文件处理 zip、gz、tar、rar
使用 linux 工作中经常遇到 zip,gz,tar 相关的压缩文件,下面整理下几种压缩文件的常用方法。
1293 0
Shell - 常用压缩文件处理 zip、gz、tar、rar
|
PHP 开发工具