zipfile.ZipFile()
zipfile.ZipFile() is a Python function in the Zipfile Module category. Opens a ZIP file for reading, writing, or appending. The syntax is zipfile.ZipFile(file, mode="r", compression=ZIP_STORED, allowZip64=True, compresslevel=None). Parameters: file, mode. Returns: ZipFile object. A typical example: import zipfile
with zipfile.ZipFile("archive.zip", "w") as z:
z.write("file1.txt")
z.write("file2.txt"). A close sibling is zipfile.ZipFile.extractall(), which extracts all ZIP contents into the current or specified directory. A close sibling is zipfile.ZipFile.extract(), which extracts a single file from the ZIP archive. A close sibling is zipfile.ZipFile.namelist(), which returns a list of all files and directories in the ZIP archive. A close sibling is zipfile.ZipFile.getinfo(), which returns information about a file in the archive (size, compress_size, date_time). More about this category: ZIP archive handling — ZipFile, extract, extractall, namelist. Related Zipfile Module entries: zipfile.ZipFile.extractall(), zipfile.ZipFile.extract(), zipfile.ZipFile.namelist(), zipfile.ZipFile.getinfo(), zipfile.ZipFile.close(), zipfile.is_zipfile(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details.