Last active
October 30, 2020 14:20
-
-
Save amacal/33d5defea6e479a398d7f47853765cad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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