zipfile.is_zipfile()
zipfile.is_zipfile() is a Python function in the Zipfile Module category. Returns True if the file is a valid ZIP file (quick check by magic number). The syntax is zipfile.is_zipfile(filename). Parameters: filename — path string. Returns: Boolean. A typical example: zipfile.is_zipfile("test.zip") # True
zipfile.is_zipfile("test.txt") # False. A close sibling is zipfile.ZipFile(), which opens a ZIP file for reading, writing, or appending. 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. More about this category: ZIP archive handling — ZipFile, extract, extractall, namelist. Related Zipfile Module entries: zipfile.ZipFile(), zipfile.ZipFile.extractall(), zipfile.ZipFile.extract(), zipfile.ZipFile.namelist(), zipfile.ZipFile.getinfo(), zipfile.ZipFile.close(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details.