On this page
  1. zipfile.is_zipfile
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

zipfile.is_zipfile

Prev: zipfile.error | Up: zipfile | Next: zipfile.LargeZipFile
Rel: zipfile.BadZipFile, zipfile.BadZipfile, zipfile.error, zipfile.LargeZipFile
Ref: docs.python.org — zipfile.is_zipfile
Tags: #public #python3 #stdlib #zipfile


Import

import zipfile
from zipfile import is_zipfile

Signature & Overview

zipfile.is_zipfile(filename)

Quickly see if a file is a ZIP file by checking the magic number.

Usage

import io
import zipfile

buf = io.BytesIO()
with zipfile.ZipFile(buf, "w") as zf:
    zf.writestr("a.txt", "1")
assert zipfile.is_zipfile(buf) is True
assert zipfile.is_zipfile(io.BytesIO(b"plain text")) is False

Gotchas

REPL Inspect

from zipfile import is_zipfile
help(is_zipfile)

Linked from

Related notes