On this page
  1. zipfile.Path
  2. Import
  3. Signature & Overview
  4. Methods & Attributes
  5. Usage
  6. Gotchas
  7. REPL Inspect

zipfile.Path

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


Import

import zipfile
from zipfile import Path

Signature & Overview

zipfile.Path(root, at='')

A :class:importlib.resources.abc.Traversable interface for zip files.

Methods & Attributes

Usage

import io
import zipfile

buf = io.BytesIO()
with zipfile.ZipFile(buf, "w") as zf:
    zf.writestr("docs/readme.txt", "hello zip path")

buf.seek(0)
with zipfile.ZipFile(buf, "r") as zf:
    root = zipfile.Path(zf)
    assert (root / "docs" / "readme.txt").read_text(encoding="utf-8") == "hello zip path"

Gotchas

REPL Inspect

from zipfile import Path
help(Path)

Linked from

Related notes