Skip to content

Instantly share code, notes, and snippets.

@amacal
Last active October 30, 2020 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amacal/33d5defea6e479a398d7f47853765cad to your computer and use it in GitHub Desktop.
Save amacal/33d5defea6e479a398d7f47853765cad to your computer and use it in GitHub Desktop.
from zipfile import ZipFile, Path
with ZipFile('python-3.9.0-docs-pdf-a4.zip') as archive:
# all-at-once way
for info in archive.infolist():
assert info.filename.startswith('docs-pdf')
# or pathlike way
root = Path(archive)
assert root.is_dir()
# even going deeper
faq = root / 'docs-pdf' / 'faq.pdf'
assert faq.exists()
# reading children
for info in root.iterdir():
assert info.name == 'docs-pdf'
# and its inner children
for inner in info.iterdir():
assert not inner.name.startswith('docs-pdf')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment