zipfile.PyZipFile

class zipfile.PyZipFile(file, mode='r', compression=0, allowZip64=False)[source]

Class to create ZIP archives with Python library files and packages.

Methods

_RealGetContents() Read in the table of contents for the ZIP file.
__del__() Call the “close()” method in case the user forgot.
__enter__()
__exit__(type, value, traceback)
__format__ default object formatter
__init__(file[, mode, compression, allowZip64]) Open the ZIP file with mode read “r”, write “w” or append “a”.
__new__((S, ...)
__reduce__ helper for pickle
__reduce_ex__ helper for pickle
__sizeof__(() -> int) size of object in memory, in bytes
__subclasshook__ Abstract classes can override this to customize issubclass().
_extract_member(member, targetpath, pwd) Extract the ZipInfo object ‘member’ to a physical file on the path targetpath.
_get_codename(pathname, basename) Return (filename, archivename) for the path.
_writecheck(zinfo) Check for errors before writing a file to the archive.
close() Close the file, and for mode “w” and “a” write the ending records.
extract(member[, path, pwd]) Extract a member from the archive to the current working directory, using its full name.
extractall([path, members, pwd]) Extract all members from the archive to the current working directory.
getinfo(name) Return the instance of ZipInfo given ‘name’.
infolist() Return a list of class ZipInfo instances for files in the archive.
namelist() Return a list of file names in the archive.
open(name[, mode, pwd]) Return file-like object for ‘name’.
printdir() Print a table of contents for the zip file.
read(name[, pwd]) Return file bytes (as a string) for name.
setpassword(pwd) Set default password for encrypted files.
testzip() Read all the files and check the CRC.
write(filename[, arcname, compress_type]) Put the bytes from filename into the archive under the name arcname.
writepy(pathname[, basename]) Add all files from “pathname” to the ZIP archive.
writestr(zinfo_or_arcname, bytes[, ...]) Write a file into the archive.

Attributes

comment The comment text associated with the ZIP file.
fp