Skip to content

Instantly share code, notes, and snippets.

@amacal
Created October 30, 2020 15:47
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/aa9493c0a5180c500b885b4ff565b8d6 to your computer and use it in GitHub Desktop.
Save amacal/aa9493c0a5180c500b885b4ff565b8d6 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:
# extract everything
archive.extractall()
# just one file
archive.extract('docs-pdf/faq.pdf', 'docs')
# pathlike way
root = Path(archive)
faq = root / 'docs-pdf' / 'faq.pdf'
# read them directly
data = faq.read_bytes()[0:4]
assert data == b'%PDF'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment